开发者

custom constraint in mvc3 application

I am creating a custom route in asp.net MVC3 application and I want to create a route constraint whi开发者_如何学Pythonch will check if the url has integer as second part of the parameter. If so, I need to redirect to different action.

product/12

product/12-2-1990


Here's how I do it.

    ''# MapRoute allows for a dynamic product ID
    routes.MapRoute("Products", "product/{id}",
                             New With {.controller = "product",
                                       .action = "index"},
                             New With {.id = "[0-9]+") ''# this forces the ID to only be a number.

Then you will create your redirect logic separately. I would recommend using an ActionFilter to do your redirect work. You write it once and it can be implemented all over.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜