LB.*_*LB. 6 asp.net asp.net-mvc 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:
App.Web.Controllers.HomeController
App.Web.Areas.Mobile.Controllers.HomeController
Run Code Online (Sandbox Code Playgroud)
我在Global.ascx.cs中为我的HomeController设置了一个默认命名空间:
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" }
);
Run Code Online (Sandbox Code Playgroud)
(已验证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 }
);
}
Run Code Online (Sandbox Code Playgroud)
因此,为什么我仍然看到错误信息?我已经建立/清理并再次运行.结果仍然相同.
这是我注册路线的方式:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 14
在您的Global.asax路线注册中有明显原因替换:
new string[] { "App.Web.Controllers.HomeController" }
Run Code Online (Sandbox Code Playgroud)
有:
new string[] { "App.Web.Controllers" }
Run Code Online (Sandbox Code Playgroud)
这是您应该在那里使用的命名空间约束,而不是特定类型.
| 归档时间: |
|
| 查看次数: |
10386 次 |
| 最近记录: |