自动添加路由参数到url
我在一页上有 2 个网址:http://host/home/list
和 http://host/home/list/1
。如果我单击第二个网址,则第一个网址将使用参数 1 进行渲染,因此 url1 等于 ulr2 (url1 = http://host/home/list/1
和 url2=http://host /home/list/1
)
我使用这样的代码
<%= Html.ActionLink("link", "DesignerFiles", "Home", null, null)%> url1
<%= Html.ActionLink("link", "DesignerFiles", "Home", new { id = 1} , null)%> url2
有什么问题?
i have 2 urls on one page: http://host/home/list
and http://host/home/list/1
. if i click on second url then first url renders with param 1, so url1 equals ulr2 (url1 = http://host/home/list/1
and url2=http://host/home/list/1
)
i use such code
<%= Html.ActionLink("link", "DesignerFiles", "Home", null, null)%> url1
<%= Html.ActionLink("link", "DesignerFiles", "Home", new { id = 1} , null)%> url2
what the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在子级别和三级导航元素方面遇到了类似的问题。 IE - 应该从 /Home/About/People 转到 /Home/About 的链接会将 /People 附加到第一个链接。我使用以下方法使其正常工作:
这似乎强制 ActionLink 不包含我视图当前上下文中的附加参数。旁注,我将默认的 {controller}/{action}/{id} 更改为 {controller}/{action}/{section} - 这就是您在我的路由值中看到部分的原因。
I had a simliar issue with sub level and tertiary navigation elements. IE - a link that should go to /Home/About from the /Home/About/People would append /People to the first link. I used the following method to get this to work correctly:
That seemed to force the ActionLink to not include the additional parameter that was in the current context of my view. Side note, I changed the dafault {controller}/{action}/{id} to {controller}/{action}/{section} - which is why you see section in my route values.