我的項目中有兩個區域。現在,當我運行程序我得到這個錯誤:發現多個類型與名爲'Home'的控制器匹配 - 在兩個不同的區域
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
);
}
順便說一句,我也控制器( 「HomeController
」)的Area
文件夾之外。這只是提供了兩個項目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" }
);
謝謝!:
我已經試過這個解決方案,但仍然不起作用
重新編輯:您必須將Default路徑向下移動(到最後一個地方)。訂單在這裏很重要。 – 2012-01-09 20:49:17
@HenkHolterman仍然沒有工作。 – fiberOptics 2012-01-10 01:45:10
目前還不清楚「不起作用」的含義。 – 2012-01-10 10:59:19