MVC下 Area和Web同名的Controller问题

错误如下图:

解决方案:

1:Area下的XXXAreaRegistration 添加:new string[] { "xxx.Areas.xxx.Controllers" }

2:RouteConfig 下添加 namespaces: new string[] { "xxx.Controllers" }

具体如下:

Area中:

   public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new string[] { "WebTest.Areas.Admin.Controllers" }
            );
        }

RouteConfig 中:

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] { "WebTest.Controllers" }
            );
        }
原文地址:https://www.cnblogs.com/zoro-zero/p/6019431.html