找到多个与名为“Home”的控制器匹配的类型,如果为此请求(“{controller}/{action}/{id}”)提供服务的路由没有指定命名空间来搜索匹配此请求的

参考文章:

        http://blog.csdn.net/chengmodelong/article/details/41890229

  https://www.cnblogs.com/zgqys1980/archive/2012/08/22/2650816.html

 

遇到这种情况是因为,出现该问题的原因是在默认的Golbal.asax.cs文件中已经注册了默认路由,而在AREAS中又注册了一个同名的Controller,也就是说areas中的Controller和最外层的Controller中有重名的

解决方案:

  1:Area下的XXXAreaRegistration 添加:new string[] { "areas中重名Controller的命名空间" }

  2:RouteConfig 下添加 namespaces: new string[] { "最外层中重名Controller的命名空间" }

 

例如:

   
context.MapRoute(
                "CPA_default",
                "CPA/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new string[] { "Exam.Web.Admin.Areas.CPA.Controllers" }
            );

 

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional },
                namespaces: new string[] { "Exam.Web.Admin.Controllers" }
            );

 

posted @ 2018-03-20 19:01  a-fei  阅读(728)  评论(0编辑  收藏  举报