thangchung
thangchung

Reputation: 2030

How can I do a multiple route constraints in ASP.NET MVC Core?

I have searched a lot on the internet to find out the way to make constraints like The Customer Id should be a guid and required so that I can end up with [HttpGet("{customerId:guid|required}")], but unluckily don't have any solution to do like this. The document from Microsoft at https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing, section Route Constraint Reference also doesn't shed light on this. Could anyone can do the multiple constraint values like what I just describe? Thank you in advance.

Upvotes: 3

Views: 1900

Answers (1)

Jason
Jason

Reputation: 311

Simply separate the constraints with colons... {customerId:guid:required}. Constraints that take parameters are also easy to use in this way... {id:int:range(100, 999)}

Upvotes: 5

Related Questions