Configure asp.net mvc localhost/Products/News to localhost/Products,News
Is it possible to use comma instead of slash in routing path. Example
localhost/products,news
instead of
l开发者_如何转开发ocalhost/products/news
Thank you!
You can map a route like this:
routes.MapRoute(
"CommaSeperated",
"{controller},{action},{id}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
Update:
I found the problem. Commas are not treated like slashes. You can skip parameters when you are using slashes but that's not the case with commas. When you use commas you have to give all that's in the route. So you should provide all 3 parameters or it will not work. http://domain.com/files,details,3 will work but http://domain.com/files,index won't. There isn't a second comma in that URL so it won't match the route. So you write another route before the first one.
routes.MapRoute(
"CommaSeperated1",
"{controller},{action}",
new { controller = "Home", action = "Index" }
);
you can try this url
ASP.NET Mvc - nullable parameters and comma as separator
精彩评论