In a ASP.NET MVC 3 application with areas (see schema below). The "Controllers" directory from the root has been deleted.
When I do this :
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
I get this 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: MyProject.Areas.Administration.Controllers.HomeController MyProject.Areas.BackEnd.Controllers.HomeController MyProject.Areas.FrontEnd.Controllers.HomeController
When I do this :
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "MyProject.Areas.Administration.Controllers" }
);
I get tis error :
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
---- Areas
|
|---- Administration
| |--- Controllers
| | |---- HomeController
| |--- Views
| |--- Index
|---- FrontEnd
| |--- Controllers
| | |---- HomeController
| |--- Views
| |--- Index
|---- BackEnd
|--- Controllers
| |---- HomeController
|--- Views
|--- Index
Update1 To start to a specific controller in the Areas, I tried this :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Areas.BackEnd.Controllers" }
);
}
Try the following:
~/Global.asax.cs
:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Controllers" }
);
}
~/Areas/Administration/AdministrationAreaRegistration.cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Administration_default",
"Administration/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Areas.Administration.Controllers" }
);
}
~/Areas/FrontEnd/FrontEndAreaRegistration.cs
:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"FrontEnd_default",
"FrontEnd/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Areas.FrontEnd.Controllers" }
);
}
Now when you request /Administration/Home/Index
, the Index
action of HomeController
in the Administration
area will be invoked and it will look for the ~/Areas/Administration/Views/Home/Index.cshtml
view. Make sure this view is present at this location. In your picture you seem to have omitted the Home
directory - ~/Areas/Administration/Views/Index.cshtml
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With