自动添加路由参数到url

发布于 2024-08-26 07:36:00 字数 456 浏览 13 评论 0原文

我在一页上有 2 个网址:http://host/home/listhttp://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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下雨或天晴 2024-09-02 07:36:00

我在子级别和三级导航元素方面遇到了类似的问题。 IE - 应该从 /Home/About/People 转到 /Home/About 的链接会将 /People 附加到第一个链接。我使用以下方法使其正常工作:

<%= Html.ActionLink("Link", "About", "Home", new with {.section = nothing}, nothing%>
<%=Html.ActionLink("Link2", "About", "Home", new with {.section = "People"}, nothing%>

这似乎强制 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:

<%= Html.ActionLink("Link", "About", "Home", new with {.section = nothing}, nothing%>
<%=Html.ActionLink("Link2", "About", "Home", new with {.section = "People"}, nothing%>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文