ASP.NET MVC routing by string id?

旧时模样 提交于 2019-12-04 01:50:52

You should take a look at using a route constraint to do this. See http://www.asp.net/mvc/tutorials/creating-a-route-constraint-cs

routes.MapRoute(
    "Product",
    "Product/{productId}",
    new {controller="Product", action="DetailsByName"},
    new {productId = @"\w+" }
 );

In the above, the constraint regex "\w+" should limit to routes that match only "word" characters (take a look at regex docs for more details on patterns used here).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!