[英]Navigating pages in Blazor
SO i want to navigate from one page to another.所以我想从一页导航到另一页。 From a list of products to a edit product view.从产品列表到编辑产品视图。 On my list page i have a link as follows.在我的列表页面上,我有一个链接如下。
<NavLink class="nav-link">
<span class="oi oi-list-rich" aria-hidden="true" id="@product.Id" @onclick="@(() => Navigate(product.Id))" style="cursor: pointer"></span> Edit @*FIX ME should link to edit product. Obviously...*@
</NavLink>
And the code is to navigate is:并且要导航的代码是:
void Navigate(long productId)
{
NavManager.NavigateTo("/editproduct/" + productId);
}
and i want to get to a page: @page "/editproduct/{id}"我想进入一个页面:@page "/editproduct/{id}"
In my opinion my code should work.在我看来,我的代码应该可以工作。 Yet im getting a: Uncaught Error: System.ArgumentException: There is no event handler associated with this event.然而我得到一个:未捕获的错误:System.ArgumentException:没有与此事件关联的事件处理程序。
when i click on my link.当我点击我的链接时。 Any ideas how to fix this ?任何想法如何解决这一问题 ?
I don't believe that the problem is the navigation itself.我不认为问题出在导航本身。 Try the navigation from two other pages (create page1 and page2) and give it a try.尝试从其他两个页面(创建 page1 和 page2)进行导航并尝试一下。 If it works properly, the problem is elsewhere in your code.如果它工作正常,则问题出在代码的其他地方。
I would give this response as a comment, but like Caveman, I don't have enough reputation.我会把这个回复作为评论,但像穴居人一样,我没有足够的声誉。
Take a look at a NavLink
in NavMenu.razor看看NavLink
中的NavLink
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
Note the href
pointing to where you want to navigate to.请注意指向您要导航到的位置的href
。
<NavLink class="nav-link" href="@($"editproduct/{product.Id}")">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.