【发布时间】:2012-01-09 11:53:48
【问题描述】:
我的项目中有两个领域。现在,当我运行程序时,出现此错误:
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:
BaseAdminMVC.Areas.BaseAdmin.Controllers.HomeController
BaseAdminMVC.Areas.TitomsAdmin.Controllers.HomeController
我在这里找到了一些来源:Multiple Controller name
但我认为它只适用于一个领域。
就我而言,我在不同领域有两个项目。希望有人能告诉我应该怎么做才能解决这个问题。
这是Global.asax 文件:
public static void RegisterRoutes(RouteCollection routes)
{
string[] namespaces = new string[] { "BaseAdminMVC.Areas.BaseAdmin.Controllers", "BaseAdminMVC.Areas.TitomsAdmin.Controllers"};
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces
);
}
顺便说一句,我在Area 文件夹之外还有控制器(“HomeController”)。这只是提供了两个项目BaseAdmin 和TitomsAdmin 的链接。
我已经尝试过这个解决方案,但仍然不起作用:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"BaseAdmin",
"BaseAdmin/{controller}/{action}",
new { controller = "Account", action = "Index" },
new string[] { "BaseAdminMVC.Areas.BaseAdmin.Controllers" }
);
routes.MapRoute(
"TitomsAdmin",
"TitomsAdmin/{controller}/{action}",
new { controller = "Home", action = "Index" },
new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" }
);
提前致谢!!
【问题讨论】:
-
重新编辑:您必须将默认路线向下移动(到最后一个位置)。顺序在这里很重要。
-
@HenkHolterman 还是没用。
-
目前还不清楚“不起作用”是什么意思。
-
是的。实际上我已经解决了这个问题,但我不知道解决方案是如何成为可能的,而第一个解决方案最有可能但没有奏效。好吧,你说得对,顺序很重要。感谢您的帮助!
标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing