ASP.NET MVC 中不明确的控制器名称

5 asp.net-mvc

我尝试在我的项目中实现 Phil 的 Areas Demo

http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx

我在现有的 MVC 项目中附加了 Areas/Blog 结构,但在项目中出现以下错误。

控制器名称Home在以下类型之间不明确:

WebMVC.Controllers.HomeController
WebMVC.Areas.Blogs.Controllers.HomeController 
Run Code Online (Sandbox Code Playgroud)

这就是我的Global.asax样子。

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapAreas("{controller}/{action}/{id}",
        "WebMVC.Areas.Blogs",
        new[] { "Blogs", "Forums" });

    routes.MapRootArea("{controller}/{action}/{id}",
        "WebMVC",
        new { controller = "Home", action = "Index", id = "" });

    //routes.MapRoute(
    //    "Default",   // Route name
    //    "{controller}/{action}/{id}",// URL with parameters
    //    new { controller = "Home", action = "Index", id = "" }  
    //            // Parameter defaults
    //);

}

protected void Application_Start()
{
    String assemblyName = Assembly.GetExecutingAssembly().CodeBase;
    String path = new Uri(assemblyName).LocalPath;
    Directory.SetCurrentDirectory(Path.GetDirectoryName(path));
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new AreaViewEngine());
              RegisterRoutes(RouteTable.Routes);
   // RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

}

Run Code Online (Sandbox Code Playgroud)

如果我删除/Areas/Blogsfrom routes.MapAreas,它会查看根的索引。

Cra*_*ntz 1

使用 WebMVC.Areas.Blogs 和 WebMVC.Areas.OtherAreaName,而不是 WebMVC.Areas.Blogs 和 WebMVC。将区域名称视为命名空间根,而不是绝对命名空间。