【发布时间】:2012-02-04 22:52:30
【问题描述】:
在带有区域的 ASP.NET MVC 3 应用程序中(参见下面的架构)。根目录下的“Controllers”目录已被删除。
当我这样做时:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
我收到此错误: 找到了与名为“Home”的控制器匹配的多种类型。 如果服务此请求的路由 ('{controller}/{action}/{id}') 没有指定命名空间来搜索与请求匹配的控制器。 如果是这种情况,请通过调用“MapRoute”的重载来注册此路由 采用“命名空间”参数的方法。 'Home' 的请求找到了以下匹配的控制器: MyProject.Areas.Administration.Controllers.HomeController MyProject.Areas.BackEnd.Controllers.HomeController MyProject.Areas.FrontEnd.Controllers.HomeController
当我这样做时:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "MyProject.Areas.Administration.Controllers" }
);
我得到 tis 错误:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
---- Areas
|
|---- Administration
| |--- Controllers
| | |---- HomeController
| |--- Views
| |--- Index
|---- FrontEnd
| |--- Controllers
| | |---- HomeController
| |--- Views
| |--- Index
|---- BackEnd
|--- Controllers
| |---- HomeController
|--- Views
|--- Index
更新1 要开始使用区域中的特定控制器,我尝试了这个:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Areas.BackEnd.Controllers" }
);
}
【问题讨论】:
标签: asp.net-mvc