我有一个带有区域的 MVC 2 站点,假设区域名称是 {Admin}
该地区和网站运作良好。
我想要做的是为该区域设置不同的默认页面。
当我打电话时 http://webSiteName 没有问题
但对于 http://webSiteName/Admin 我收到错误
The resource cannot be found
我尝试了来自 ASP.NET MVC 2 RC 2 returns Area-specific controller when no area specified 的解决方案
但没有运气。
我也试过
routes.MapRoute(
"Admin",
"{controller}/{action}/{id}",
new { controller = "AdminHome", action = "index" },
new[] { "Web.Areas.Admin.Controllers" }
);
和
routes.MapRoute(
"Admin",
"Admin",
new { controller = "AdminHome", action = "index" },
new string[] { "Web.Areas.Admin.Controllers" }
);
但我仍然收到 无法找到该资源。
我究竟做错了什么?
最佳答案
尝试这个。确保它位于 /Areas/Admin/AdminAreaRegistration.cs
当您的区域被命名为 Admin
.
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "AdminHome",action = "Index", id = "" }
);
}
您无需在
Global.asax
中添加任何内容.
关于asp.net-mvc - asp.net mvc 区域默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3298325/