November 2016
Intermediate to advanced
326 pages
6h 1m
English
Route Constraints enable you to constrain the type of values that you pass to the controller action. For example, if you want to restrict the value to be passed to the int type int, you can do so. The following is one such instance:
[HttpGet("details/{id:int?}")]
public IActionResult Details(int id)
{
return View();
}
ASP.NET 5 (ASP.NET Core) even supports default parameter values so that you can pass the default parameters:
[HttpGet("details/{id:int = 123}")]
public IActionResult Details(int id)
{
return View();
}
Read now
Unlock full access