Reputation: 11
I have some problems when I have same controller name in separate projects. My main solution is Web forms, and I have two MVC separate projects(separate folder) , the problem If I have a controller in first project with name HomePage and same controller name in solution 2 I have an error: Multiple types were found that match the controller named 'HomePage'. This can happen if the route that services this request ('{*pathInfo}') 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 'HomePage' has found the following matching controllers: Project1.Controllers.HomePageController Project2.Controllers.HomePageController
The global.asa is in the web forms solution which I added two routes map but I still have same error. Any solution to fix this issue? Can I can in the view the action with namespace @Html.Action("index", "HomePage") Thank you
Upvotes: 1
Views: 1149
Reputation: 876
If you need to set the namespaces value when registering the route, you should do so like this:
routes.MapRoute(
name: "RouteName",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "MyNamespace.Controllers" });
By specifying the namespace, it removes the ambiguity.
Upvotes: 2