【发布时间】:2011-06-20 22:27:48
【问题描述】:
我正在 MVC3 应用程序的主 _Layout.cshtml 文件中创建一个链接。
@Html.ActionLink("Security", "Index", "Home", new { area = "Security" }, new { })
当页面被渲染时,这是生成的 Html
<a href="/Security">Security</a>
如果我点击这个链接,我会得到一个空白页。
我安装了routedebugger,结果如下:
我在 Global.ascx.cs 中有如下默认路由:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Eis.Mvc.Web" }// Parameter defaults
);
以及安全区的路线:
context.MapRoute(
"Security_default",
"Security/{controller}/{action}/{id}",
new { area = "Security", controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Eis.Mvc.Web.Areas.Security.Controllers" }
);
如果我直接输入以下 URL,http://localhost:1410/Security/home,则会显示正确的页面。
如何让@Html.Action 链接包含 URL 的控制器部分?
我确实有一个 Home 控制器,在应用程序的根部分中有一个 Index 操作,并且必须在路由注册中包含命名空间过滤器。
谢谢你, 基思
【问题讨论】:
标签: asp.net-mvc-routing html.actionlink routedebugger