自动将路由参数添加到url

时间:2010-03-22 21:14:37

标签: asp.net-mvc hyperlink asp.net-mvc-routing

我在一个页面上有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

问题是什么?

1 个答案:

答案 0 :(得分:0)

我对子级别和三级导航元素有一个类似的问题。 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不包含我视图当前上下文中的附加参数。旁注,我将dafault {controller} / {action} / {id}更改为{controller} / {action} / {section} - 这就是您在路线值中看到部分的原因。

相关问题