html.actionlink 的网址错误
我是做了分页系统。一切都好。 单击第二页后,所有主页链接都会更改。
@Html.ActionLink("Home page", "Index", "Home") //This is standard routing without values.
我在页面末尾添加了分页链接。
@Html.ActionLink("2", "Index", "Home", New With {.id = 2}, Nothing) //This works good too.
我的问题是,当我单击第二个或更多页面(例如:www.site.com/Home/Index/2)时,我的所有主页链接都转换为
<a href="/Home/Index/2">Home page</a>
相同的。 我该如何解决这个问题?
I was made paging system. Everything is OK.
After click 2nd page all homepage links changing.
@Html.ActionLink("Home page", "Index", "Home") //This is standard routing without values.
I was added paging links to end of page.
@Html.ActionLink("2", "Index", "Home", New With {.id = 2}, Nothing) //This works good too.
My problem is when I click to 2nd or more page (e.g : www.site.com/Home/Index/2) my all homepage links converting to
<a href="/Home/Index/2">Home page</a>
same this.
How I can resolve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您点击第二页时,
{.id = 2}
将成为您的 RouteData 的一部分。因为您的路由可能如下所示:(在 Gloabal.asax 中)ASP.NET MVC 将使用此路由来生成链接。因此它将包含 Id = 2。要解决此问题,您需要在不需要时显式覆盖它:
When you click on the 2nd page the
{.id = 2}
will be part of your RouteData. And because your routing probably looks like this: (in Gloabal.asax)ASP.NET MVC will use this route for the generated links. So it will include Id = 2. To fix this you need to explicitly override it when it's not needed: