Route Constraints

The following table lists the options for constraining route parameters by data type and range.

Note that it is also possible to create your own custom constraint

Constraint Description Example
alpha Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z) {title:alpha}
bool 1 Matches a Boolean value. {isActive:bool}
int 1 Matches a 32-bit integer value. {id:int}
datetime 1 Matches a DateTime value. {startdate:datetime}
decimal 1 Matches a decimal value. {cost:decimal}
double 1 Matches a 64-bit floating-point value. {latitude:double}
float 1 Matches a 32-bit floating-point value. {x:float}
long 1 Matches a 64-bit integer value. {x:long}
guid 1 Matches a GUID value. {id:guid}
length Matches a string with the specified length or within a specified range of lengths. {key:length(8)} {postcode:length(6,8)}
min Matches an integer with a minimum value. {age:min(18)}
max Matches an integer with a maximum value. {height:max(10)}
minlength Matches a string with a minimum length. {title:minlength(2)}
maxlength Matches a string with a maximum length. {postcode:maxlength(8)}
range Matches an integer within a range of values. {month:range(1,12)}
regex Matches a regular expression. {postcode:regex(^[A-Z]{2}\d\s?\d[A-Z]{2}$)}

Notes

  1. Can be made optional by adding ? after the constraint e.g id:int?
Last updated: 20/08/2019 10:03:58

On this page

© 2019 - Learn Razor Pages.
All rights reserved.