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.

DaveRandom
88.8k11 gold badges160 silver badges174 bronze badges
asked May 2, 2010 at 22:14

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"];
 }
}
answered May 2, 2010 at 22:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.