多种类型的发现相匹配命名为'家'的控制器 - 在两个不同的领域 [英] Multiple types were found that match the controller named 'Home' - In two different Areas
问题描述
我在我的项目的两个领域。现在,当我运行程序我得到这个错误:
I have two areas in my project. Now when I run the program I get this error:
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
我已经在这里找到了一些来源:<一个href=\"http://stackoverflow.com/questions/5092589/having-issue-with-multiple-controllers-of-the-same-name-in-my-project\">Multiple控制器名称结果
但我认为它仅适用于一个区域。结果
在我来说,我在不同领域的两个项目。希望有人能告诉我应该怎么做才能解决这个问题。结果
这里是的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
)的区
文件夹之外。这只是提供链接到两个项目 BaseAdmin
和 TitomsAdmin
。
By the way, I have also controller ("HomeController
") outside the Area
folder. This just provides links to two projects BaseAdmin
and TitomsAdmin
.
我曾尝试这种解决方案,但仍不起作用
I have tried this solution, but still doesn't work:
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" }
);
在此先感谢!
推荐答案
我不知道发生了什么,但是这code正常工作:
I don't know what happen, but this code works fine:
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 = UrlParameter.Optional },
new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" }
);
}
这篇关于多种类型的发现相匹配命名为'家'的控制器 - 在两个不同的领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!