Route Constraints

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(); 
    } 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset