MVC3 Routing question
I just started to use the routes in MVC3 and I am totally confused. I hope I can get some advice on how I can do what I need from this site. Here is what I would like to do. First and most important I need all these links to go to the Product controller.
www.xx.com/product 12 code/ >> Action: Overview,
>> ProdId=12 passed as a param
www.xx.com/product 12 code/Overview >> Action: Overview,
>> ProdId=12 passed as a param
www.xx.com/product 12 code/Results >> Action: Results,
>> ProdId=12 passed as a param
www.xx.com/product 12 code/Product >> Action: Product,
>> ProdId=12 passed as a param
>> Code="" passed as a param
www.xx.com/product 12 code/Product/123 >> Action: Index,
>> ProdId=12 passed as a param
>> Code= 123 passed as a param
What I learned already is that I can get the "12" like this:
routes.MapRoute("Route 1", // Route name
"product {prodId} code/{action}/{id}",
new
{
controller = "Product",
开发者_如何转开发 action = "Index",
id = UrlParameter.Optional
}
);
But how can I make it go to the different action events and pass the prodId and id as parameters? I think the route system is very powerful but complicated for a new user like me. How many routes do I need to set up to do what I need?
routes.MapRoute("Route 1", // Route name
"product {prodId}/{action}/{code}",
new
{
controller = "Product", //default controller=Product
action = "Index", //default action= Index
prodId = 12, //default prodId=12
code=UrlParameter.Optional // code is optional
}
);
www.xx.com/product 12/ >> Action: Overview,
>> ProdId=12 passed as a param
www.xx.com/product 12/Overview >> Action: Overview,
>> ProdId=12 passed as a param
www.xx.com/product 12/Results >> Action: Results,
>> ProdId=12 passed as a param
www.xx.com/product 12/Product >> Action: Product,
>> ProdId=12 passed as a param
>> Code="" passed as a param
www.xx.com/product 12/Product/123 >> Action: Index,
>> ProdId=12 passed as a param
>> Code= 123 passed as a param
精彩评论