Reputation: 6875
I have two class library project and an mvc Web UI project like this.
I configured UI Route config like this.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Blog",
"{controller}/{action}/{id}",
new {controller="Home", action = "Index",id = UrlParameter.Optional },
new[] { "Separated.Blog.Controller" });
routes.MapRoute("Admin",
"{controller}/{action}/{id}",
new{controller="Home",action="Index",id = UrlParameter.Optional },
new[] { "Separated.Admin.Controller" });
}
namespace Separated.Admin.Controller.Controllers
{
public class HomeController:System.Web.Mvc.Controller
{
public ActionResult Index()
{
return Content("This is Admin index page");
}
}
}
namespace Separated.Blog.Controller.Controllers
{
public class HomeController: System.Web.Mvc.Controller
{
public ActionResult Index()
{
return Content("This is Blog index page...");
}
}
}
When I run project, gives error as following:
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: Separated.Admin.Controller.Controllers.HomeController Separated.Blog.Controller.Controllers.HomeController
I want to start up with Blog Home controller like localhost/Home/Index. And call Admin controller localhost/Admin/Home/Index
Upvotes: 0
Views: 142
Reputation: 2648
Every Area has it's own AreaRegistration class.There you need to make change and set your controller action.
This how you call for Area's controller action
'@Url.Action("ActionName", "Controller", new { Area="YourAreaName"})'
Upvotes: 0