【发布时间】:2011-03-29 15:51:06
【问题描述】:
我正在尝试使用 Maarten Balliauw 的 Domain Route 类将子域映射到 MVC2 应用程序中的区域,以便我拥有如下 URL:
http://admin.mydomain.com/home/index
代替:
http://mydomain.com/admin/home/index
到目前为止,我只取得了部分成功。执行被路由到正确区域中的正确控制器,但它无法找到正确的视图。我收到以下错误:
The view 'Index' or its master was not found. The following locations were searched:
~/Views/AdminHome/Index.aspx
~/Views/AdminHome/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
这表明 MVC 仅在根视图文件夹中查找视图,而不是区域内的视图文件夹。如果我将视图从区域的视图文件夹复制到根视图文件夹,则页面呈现良好。然而,这完全违背了将 APP 划分为区域的目的。
我将该区域的路线定义为:
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Admin"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.Add(
"Admin_Default"
, new DomainRoute(
"admin.localhost"
, "{controller}/{action}/{id}"
, new { controller = "AdminHome", action = "Index", id = UrlParameter.Optional }
));
}
}
我很困惑为什么它可以在区域内找到控制器,但不是视图。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 asp.net-mvc-routing