使用自定义路由时 Actionlinks 添加错误参数
我正在使用此自定义路由在 Home 控制器中的索引方法中启用分页:
routes.MapRoute( _
"HomePage", _
"Home/Index/{page_num}", _
New With {.controller = "Home", .action = "Index", .page_num = ""} _
)
但是当我导航到任何页面(例如第 2 页)时,actionlinks 将页码附加到 url:
Html.ActionLink("Home", "Index", "Home")
将呈现 _http://localhost/Home/Index/ 2 而不是 _http://localhost/Home/Index
但我注意到没有参数的操作方法可以正确呈现: _http://localhost/Home/关于
I am using this custom route to enable paging in my index method in Home controller:
routes.MapRoute( _
"HomePage", _
"Home/Index/{page_num}", _
New With {.controller = "Home", .action = "Index", .page_num = ""} _
)
But when I navigate to any page for example page 2, actionlinks append the page number to the url:
Html.ActionLink("Home", "Index", "Home")
will render _http://localhost/Home/Index/2 instead of _http://localhost/Home/Index
But I've noticed that action methods without parameters renders correctly:
_http://localhost/Home/About
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Html.ActionLink 使用先前路由值字典中的 page_num 参数,除非您更改 page_num 留下的一些参数。
如果您有如下所示的路线:
Html.ActionLink("Home","about") 将清除 page_num 变量,您将获得类似 /home/about 而不是 /home/about/2 的 url。
查看此相关问题。也许会有帮助。
Html.ActionLink uses page_num parameter from previous route value dictionary unless you change some parameters left to page_num.
If you had the route like below:
Html.ActionLink("Home","about") will clear page_num variable and you will get url like /home/about instead of /home/about/2.
Look at this related Question. Maybe it would help.