Route Constraint
noun
say it: “ROWT kun-STRAYNT” /raʊt kənˈstreɪnt/
A rule on a route value, such as {id:int}, that the address must match for the route to be chosen.
What is Route Constraint in ASP.NET Core?
Route Constraint — A rule after a colon in a route value, such as {id:int}, that the address must match before the route is chosen. /products/7 matches; /products/chai doesn't, so it goes to another route or a 404.
[HttpGet("products/{id:int}")]
public IActionResult Details(int id) => View(productDao.GetById(id));
In a sentence
- “The route constraint {id:int} sends /products/chai somewhere else instead of crashing.”
Level: Journeyman · More ASP.NET Core terms at this level
Updated