ASP.NET MVC 相同Controller的解决办法

今天做的MVC程序里,有两个WebSite,有两个不同命名空间的HomeController,网站启动时,/Home/Index, 提示有两个HomeController. 系统不知道使用哪一个

register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

解决办法:

1. 在路由注册时,加上各自的命名空间

routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional },null, new string[]{"Video.CMS.Controller.*"}

2. 在Application_Start里

AreaRegistration.RegisterAllAreas();

RegisterRoutes(RouteTable.Routes);

之后加上:

ControllerBuilder.Current.DefaultNamespaces.Add("Video.CMS.Controller.*");

原文地址:https://www.cnblogs.com/cnblogsfans/p/2135335.html