fib*_*ics 14 c# asp.net-mvc asp.net-mvc-routing asp.net-mvc-3
我的项目有两个方面.现在,当我运行程序时,我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
我在这里找到了一些来源:多个控制器名称
但我认为它只适用于一个区域.
就我而言,我在不同领域有两个项目.希望有人能告诉我该怎么做才能解决问题.
这是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
);
}
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我还有文件夹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" }
);
Run Code Online (Sandbox Code Playgroud)
提前致谢!!
fib*_*ics 18
我不知道发生了什么,但这段代码工作正常:
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" }
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22295 次 |
| 最近记录: |