问题重现:
当项目下:Controller/HomeController.cs时,
运行报错:
Server Error in '/' Application.
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:
Fckeditor.Controllers.HomeController
MvcApplication2.Controllers.HomeController
解决办法:
/Global.asax
代码
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//在Global.asax的MapRoute也加入了这个命名空间
routes.MapRoute(
"Home",
"{controller}/{action}/{id}",
new { Controller="Home",Action="index",id=UrlParameter.Optional},
new string[] { "MvcApplication2.Controllers" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "CreateTools", id = UrlParameter.Optional } // Parameter defaults
);
}