cdi*_*die 6 c# asp.net asp.net-mvc asp.net-core blazor-server-side
我在 ASP.NET Core MVC 3.1 网站上使用 Blazor 服务器来处理某些需要 Blazor 功能的组件。一切正常,但是,我无法从 Blazor 组件导航到 ASP.NET MVC 路由。
为了导航,我设置了以下属性:
[Inject]
public NavigationManager NavigationManager { get; set; }
Run Code Online (Sandbox Code Playgroud)
当我打电话时NavigationManager.NavigateTo("/games/details/" + gameId, true),出现以下错误:
错误:System.InvalidOperationException:“RemoteNavigationManager”尚未初始化。在 Microsoft.AspNetCore.Components.NavigationManager.AssertInitialized() 在 Microsoft.AspNetCore.Components.NavigationManager.NavigateTo(String uri, Boolean forceLoad) 在 MyWebSite.Web.Pages.Search.SearchBar.GoToGamePage(Int32 gameId) 在 D:\repos \MyWebSite\src\MyWebSite.Web\Pages\Search\SearchBar.razor.cs: 第 58 行位于 D:\repos\MyWebSite\src\MyWebSite 中的 MyWebSite.Web.Pages.Search.SearchBar.<>c__DisplayClass47_0.b__5() .Web\Pages\Search\SearchBar.razor:第 22 行,位于 Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T](MulticastDelegate 委托,T arg),位于 Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent。 Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId、EventFieldInfo fieldInfo、EventArgs eventArgs)的 HandleEventAsync(EventCallbackWorkItem 回调,对象 arg)
我发现的有关 NavigationManager 的所有内容都适用于 Blazor Web 项目,而不是带有 Blazor 组件的 ASP.NET Core MVC。
小智 -3
将其插入文件顶部.razor:
@inject NavigationManager navigationmanager
Run Code Online (Sandbox Code Playgroud)
然后你可以说
navigationmanager.NavigateTo("/games/details/" + gameId, true)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5717 次 |
| 最近记录: |