0

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.

1 Answer 1

1

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"];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.