代码改变世界

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

2011-08-11 17:44  敏捷的水  阅读(2197)  评论(3编辑  收藏  举报

 

今天做的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.*");