MVC for everything that is only numeric

I need help limiting:

Constraints = new RouteValueDictionary(new { filename = @"" })

      

It should be numeric only (no letters, slashes, etc.).

0


source to share


1 answer


I'm not sure I understood this question, but as far as I know you can just provide regexes in a constraint dictionary.

I think there is even an example for this in MSDN Mode :

reportRoute.Constraints = new RouteValueDictionary { 
  { "locale", "[a-z]{2}-[a-z]{2}" }, 
  { "year", @"\d{4}" } };

      



based on this, I think you should write:

Constraints = new RouteValueDictionary(new { filename = @"\d+" })

      

+4


source







All Articles