假设我在页面"主页/索引",我想转到页面MyOtherController/Index/1
我怎样才能做到这一点 ?
我尝试:
<%= Html.ActionLink("Test", "Index", "MyOtherController", new { id=item.Id }) %>
我是否还必须在Global.aspx文件中添加路由?
一种选择是在routevalues列表中指定控制器的名称:
<%= Html.ActionLink("Test", "Index"
, new { controller = "MyOtherController", id = item.Id }) %>Run Code Online (Sandbox Code Playgroud)
一个替代方案是使用过载ActionLink带htmlAttributes = null:
<%= Html.ActionLink("Test", "Index"
, "MyOtherController", new { id = item.Id }, null) %>Run Code Online (Sandbox Code Playgroud)
在这种情况下,ASP.NET MVC模板中的默认路由负责路由.
| 归档时间: |
|
| 查看次数: |
4902 次 |
| 最近记录: |