0

How to use regular expression to add rules in routing in mvc4. I want to add some validation rules to my route. I am using asp.net mvc4 application.

1

1 Answer 1

0

Thing you are looking for is called Constraint for route. You specify the constraint to your route definition as:

routes.MapRoute(
name: "somthing",
url: "{controller}/{id}",
defaults: new { controller = "Home", action = "index", id = UrlParameter.Optional },
constraints: new { id = @"^[0-9]+$" }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.