简体   繁体   中英

asp.net mvc routing, with area as parameter

I'm building a website for multiple organizations. For example, people could go to mydomain.com/org1/home/index or mydomain.com/org2/home/index.

What I am trying to do is have the following routing,

mydomain.com/{area}/{controller}/{action}/{id}

I can't figure out how to do this, and frankly not even sure how to even start setting up my routing. I want to be able to access {area} string in order to decide which images to display, what text etc.

I hope I'm making sense with what I'm trying to do.

routes.MapRoute(
name: "Default",
url: "{area}/{controller}/{action}/{id}"
defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
area = UrlParameter.Optional
);

Your Home controller will look something like this:

public ActionResult Index(string area, string id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM