Reputation: 1
I am an MVC newbie. I'm trying to get my URLs to look like this:
/Corporate/Users/Edit/1
/Corporate/Stores/Edit/17
/Corporate/Contacts/Edit/17
/Store/Contacts/Create
/Store/Products/Edit/29
Pretty much like plain-vanilla urls, except with a user type at the front. I'm running into a lot of problems with duplicate controller names, etc.
Is there a simple way to do this? I looked briefly at Areas, but this seemed way to complicated.
Upvotes: 0
Views: 86
Reputation: 31842
You can try:
routes.MapRoute(
RouteNames.Default, // Route name
"{userType}/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
and then
public ActionResult LogIn(string userType)
{
return View();
}
or
public ActionResult LogIn()
{
var userType = RouteData.Values["userType"];
return View();
}
where needed or define BaseController:
public class BaseController : Controller
{
private string _userType;
public BaseController()
{
_userType = RouteData.Values["userType"];
}
}
Upvotes: 1