c# - Is it possible to have multiple MVC routes point to the same controller/view? -


(disclaimer: new mvc)

i trying setup website product listing categories lets user request pages both productfolder/productname , productfolder/category/productname. possible?

the closest have gotten far adding following routeconfig.cs registerroutes method, , placed productnameone.cshtml in views\products solution folder. results in being able see '.../products/index' , '.../products/productnameone' pages '.../products/categoryone/productnameone' returns 404

routes.ignoreroute("{resource}.axd/{*pathinfo}");  routes.maproute(name: "products", url: "products/{action}/{id}",             defaults: new { controller = "products", action = "index", id =              urlparameter.optional });   routes.maproute(name: "categoryoneproducts", url: "products/categoryone/{action}/{id}",             defaults: new { controller = "products", action = "productnameone", id =              urlparameter.optional });  routes.maproute(             name: "default",             url: "{controller}/{action}/{id}",             defaults: new { controller = "home", action = "index", id = urlparameter.optional }); 

you need order routes most specific route first.

i'm guessing 404 url matching first route, , blowing because categoryone not exist id.

reorder routes categoryone route tried first:

routes.maproute(name: "categoryoneproducts", url: "products/categoryone/{action}/{id}",         defaults: new { controller = "products", action = "productnameone", id =          urlparameter.optional });  routes.maproute(name: "products", url: "products/{action}/{id}",         defaults: new { controller = "products", action = "index", id =          urlparameter.optional }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -