Question

I have a web site in MVC4 with area "admin" inside controller named "HomeController" ,also in my project a folder controller with controller named "HomeController" : when I do a call to

public ActionResult LogOff()
{
    FormsAuthentication.SignOut();
    return RedirectToAction("Index", "Home");
}

I get error : Multiple types were found that match the controller named 'Home'. 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.

The request for 'Home' has found the following matching controllers: site1.co.il.Controllers.HomeController site1.co.il.Areas.Admin.Controllers.HomeController

Was it helpful?

Solution

If you have the same controller and action in different areas, MVC4 has no way to choose one of them, unless you specify which is the desired route.

You can specify it like this:

return RedirectToAction("action", "controller", new { area = "area" });

In your case area should be "admin"

If you want to refer to the root Controller, area should be ""

You can also try to refer to the appropriate controller like this: "admin\home", but I don't know if the equivalent "\home" would work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top