locked
getting an error when trying to use NavigationManager.NavigateTo RRS feed

  • Question

  • User351619809 posted

    Hello All,

    I am trying to navigate to another page using NavigationManager.NavigateTo and I keep getting this error saying:

       "An object reference is required for the non-static field, method, or property 
        'NavigationManager.NavigateTo(string, bool)'
    

    when the user clicks on the table row then I am calling this method :

    @code{
       private void RowSelected(int itemId)
        {
    
            NavigationManager.NavigateTo($"projectedit/{itemId}");
        }
    
       private  void OnRowClickHandler(GridRowClickEventArgs args)
        {
    
            await RowSelected(( args.Item as AllItProjectsList).ProjectId);
        }
    }
    

    My Projectedit partial class is like so:

    protected override async Task OnInitializedAsync()
            {
    
                Saved = false;
    
                BSA = (await bSADataService.GetAllBSA()).ToList();
                Appdev = (await appDevDataService.GetAllAppDev()).ToList();
    
                int.TryParse(ProjectId, out var projectId);
    
                if (projectId == 0) //new employee is being created
                {
                    //add some defaults
                    Project = new AllItProjectsList { ProjectId = 1, test = "", AppDev = " ", Description = "", Name = "Test" };
                }
                else
                {
                    Project = await ITprojectDataService.GetAllITProjectDetails(int.Parse(ProjectId));
                }
    
                BsaId = Project.ProjectId.ToString();
                AppDevId = Project.Appdevid.ToString();
    
            }
    

    I don't have anything defined as static so not sure why this error keeps coming.

    any help will be appreciated.

    Wednesday, May 12, 2021 8:37 PM

Answers