Hands-On Full-Stack Web Development with ASP.NET Core
by Tamir Dresher, Amir Zuker, Shay Friedman
Constraints
Inline constraints inside the routing attributes are used by placing a colon with the constraint name :constraint-name after the route parameter name, where constraint-name is a constraint that you define by creating a class that implements the IRouteConstraint interface, or simply by using one of the built-in constraints specified in the ASP.NET documentation, available at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?highlight=routing#route-constraint-reference.
The following example shows how we can add a search method to our ProductsController that searches by the date that the product was posted online. The URL for this action must constrain the date parameter to datetime formats only; therefore, we will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access