So I am using MVC 5, and is getting this error. This is because I have two areas and they both have a controller with the same name and same method name.
Multiple types were found that match the controller named 'controller1'.
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.
So I understand that I need to add name spaces to my routing. So in Route.config.cs
I added this
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "webApp.Controllers" }
);
Then in the application_start()
function in global.asax
I added ControllerBuilder.Current.DefaultNamespaces.Add("webApp.Controllers");
Then in my areas, where my error is coming from. I have 2 areas, admin and myportal. Both have a AreaRegistration.cs file. In AdminAreaRegistration.cs I have this added
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
defaults: new { action = "Index", id = UrlParameter.Optional },
new[] { "webApp.Areas.Admin.Controllers" }
);
}
In MyPortalAreaRegistration.cs I have this added
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"MyPortal_default",
"MyPortal/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "webApp.Areas.MyPortal.Controllers" }
);
}
From the client side I am making a post call
const otherParams = {
headers: {
"content-type": "application/json; charset=UTF-8"
},
body: JSON.stringify(product),
method: 'POST'
};
console.log(otherParams);
const response = await fetch('/Item/GetDetailPageURL', otherParams)
.then(response => {
response.json();
console.log(response);
window.open(response.url, "_blank");
})
.then(data => console.log(data));
From what I understand this is all I needed to get it work, but it is still complaining about the namespace. Am I misunderstanding/ missing something?