Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stormwild/8838729 to your computer and use it in GitHub Desktop.
Save stormwild/8838729 to your computer and use it in GitHub Desktop.

Multiple types were found that match the controller named 'Controller name'.

In Application\App_Start\RouteConfig.cs, add a fourth parameter for namespaces:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new[] { "AskPLDT.Controllers" }
);

http://stackoverflow.com/questions/7842293/multiple-types-were-found-that-match-the-controller-named-home

This error message often happens when you use areas and you have the same controller name inside the area and the root. For example you have the two:

~/Controllers/HomeController.cs
~/Areas/Admin/Controllers/HomeController.cs

In order to resolve this issue (as the error message suggests you), you could use namespaces when declaring your routes. So in the main route definition in Global.asax:

routes.MapRoute(
  "Default",
  "{controller}/{action}/{id}",
  new { controller = "Home", action = "Index", id = UrlParameter.Optional },
  new[] { "AppName.Controllers" }
);

and in your ~/Areas/Admin/AdminAreaRegistration.cs:

context.MapRoute(
  "Admin_default",
  "Admin/{controller}/{action}/{id}",
  new { action = "Index", id = UrlParameter.Optional },
  new[] { "AppName.Areas.Admin.Controllers" }
);            

In ASP MVC 4.0 you need to pass named argument like

namespaces: new[] {"AppName.Areas.Admin.Controllers" }    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment