Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
ASP.NET Core 2 Fundamentals

You're reading from   ASP.NET Core 2 Fundamentals Build cross-platform apps and dynamic web services with this server-side web application framework

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781789538915
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
 Gumus Gumus
Author Profile Icon Gumus
Gumus
 T. S. Ragupathi T. S. Ragupathi
Author Profile Icon T. S. Ragupathi
T. S. Ragupathi
Arrow right icon
View More author details
Toc

Route Constraints


Route Constraints enable you to constrain the type of values that you pass to the controller action. It is all about action selection for routing. So, we can say one action should trigger for integer input whereas another should trigger for non-integers. For example, if you want to restrict the value to be passed to the int type, you can do so. The following is one such instance:

[HttpGet("details2/{id:int}")]
  public IActionResult Details2(int id = 123)
  {
    return View();
  }

ASP.NET Core even supports default parameter values so that you can pass the default parameters:

[HttpGet("details2/{id:int}")]
  public IActionResult Details2(int id = 123)
  {
    return View();
  }

There are many constraints available, such as int and bool.

Activity: Creating an Attribute that Implements IActionConstraintFactory

Scenario

By using IActionConstraint and IActionConstraintFactory interfaces we can add custom constraints. Create an attribute that implements IActionConstraintFactory and...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images