1

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

4
  • 2
    How are you registering the routes? Show us some code so we can help you, thanks. Commented Jan 25, 2016 at 14:49
  • 1
    Does one of the MVC projects reference the other? The routing framework merely collects all controllers from all available namespaces and then tries to find a matching route. Therefore, it doesn't matter if it's different projects if one references the other. Commented Jan 25, 2016 at 15:28
  • Yeah I tried but it take only the first route the second have same error Commented Jan 25, 2016 at 19:28
  • no reference between the 2 MVC projects, the project1 have url like www.project1.com and the second is www.project2.com when i add route it work only for the first one Commented Jan 25, 2016 at 19:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried to add namespace for both but the problem the application take always the first route
Can you edit your original post and include the RegisterRoutes code so that we can see where the conflict might be?
I fixed, the solution is : The second project should have an area , the first one is optional to have it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.