首页 新闻 会员 周边 捐助

ASP.NET MVC错误

0
悬赏园豆:20 [已关闭问题] 关闭于 2010-03-31 11:29

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
B2CMVC.Controllers.HomeController
B2CMVC.Areas.user.Controllers.HomeController

羽鱼的主页 羽鱼 | 初学一级 | 园豆:134
提问于:2010-03-31 10:18
< >
分享
所有回答(1)
0

使用Area出现错误:Multiple types were found that match the controller named 'Home'

 

只需要在你的global.asax中的routes.MapRoute()方法中,添加一个默认的命名空间,如: 

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

           routes.MapRoute( 
               "Default",                                              // Route name 
               "{controller}/{action}/{id}",                           // URL with parameters 
               new { controller = "Home", action = "Index", id = "" },  // Parameter defaults 
               new[] { "MvcTest.Web.Controllers" } 
           ); 

       } 

注意上面的new[] { "MvcTest.Web.Controllers" }参数,在Area的对应AreaRegistration.cs类中的routes.MapRoute方法中,也加入这个参数,不同的是字符串要改写成Area的Controller对应的命名空间,如new[] { "MvcTest.Web.Areas.TestArea.Controllers" }

万事俱备就差个程序员 | 园豆:229 (菜鸟二级) | 2014-12-14 14:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册