做毕业设计过程中遇到的问题之一

1.找到了多个与名为“Home”的控制器匹配的类型

通过百度发现很多人都出现过这种情况

出现原因:在默认的Golbal.asax.cs文件中已经注册了默认路由,而在AREAS中又注册了一个同名的Controller,areas中的Controller和最外层的Controller中有重名的

解决方案:

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

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

例如:

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces:new string[] { "OnlineBookStore.Controllers" }
);

context.MapRoute(
"BackEnd_default",
"BackEnd/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new string[] { "OnlineBookStore.Areas.BackEnd.Controllers" }

参考文章:https://www.cnblogs.com/dansediao/p/8611525.html

原文地址:https://www.cnblogs.com/oner-xd/p/12336553.html