3

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.

2
  • I think it can be acheived by using required in route condition {customerId:required} and in action you can specify type of incomming customerId like Get([FromRoute]Guid customerId), later you can also check ModelState.IsValid Commented Dec 7, 2017 at 14:53
  • Where's the documentation for this? Commented Oct 31, 2019 at 15:00

1 Answer 1

5

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)}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.