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-1990Here'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.
精彩评论