这可能对许多人来说都是重复的,但是其中明显的答案并不能解决我的问题。
我得到:
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:
App.Web.Controllers.HomeController
App.Web.Areas.Mobile.Controllers.HomeController
我在Global.ascx.cs中为我的HomeController设置了默认 namespace :
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "App.Web.Controllers.HomeController" }
);
(验证App.Web.Controllers.HomeController不是错字)。
并且还在MobileAreaRegistration中注册了Mobile的HomeController:
public override void RegisterArea(AreaRegistrationContext context) {
context.MapRoute(
"Mobile_default",
"Mobile/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
因此,为什么仍然看到错误消息?我已经盖好/打扫好了,然后又跑了。结果还是一样。
这是我注册路线的方式:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
最佳答案
出于明显原因,请在您的Global.asax路由注册中替换:
new string[] { "App.Web.Controllers.HomeController" }
和:
new string[] { "App.Web.Controllers" }
那是您应在此处使用的 namespace 约束,而不是特定的类型。
关于asp.net - 发现了多种与名为 'Home'的 Controller 匹配的类型。 (两个区域,相同的 Controller 名称),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956912/