I have placed all my admin controllers inside an Admin folder in Controller folder. Since one of my admin controller matches the name of another controller in Controller folder, I am getting the following error.
Multiple types were found that match the controller named ‘Product’. 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.
I tried adding the following route, but still the problem is same
routes.MapRoute(
"", //Route name
"Admin/{controller}/{action}/{id}", // Url with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
How can i get rid of this error. Changing the name of controller is the last option on my mind. Right now, I am looking for a way to preserve the name and see if i can find another way around this.
Well, that’s your problem. How do you expect the default controller factory to know which controller you want to be instantiated given the following request
/admin/index(the one in the Controllers folder or the on in the Controllers/Admin folder)? Remember that the default controller factory searches for types in the loaded assemblies that derive from Controller. It doesn’t really care in which folder they were declared. So when it finds that you have 2 controllers with the same name it doesn’t know which one to pick.One possibility is to use Areas. Then you could specify namespaces when registering the route:
Also in your Global.asax make sure that you specify the namespace for the non-area controllers: