We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi.
Is it possible to configure AttributeRouting so that some parameter would be formatted using specific format? For example, I have an action:
[GET("{year:int:length(4)}-{month:range(1, 12)}")] public ActionResult Days(int year, int month)
I want the month parameter to be always two-digit. How to achieve that with AttributeRouting?
month
The text was updated successfully, but these errors were encountered:
If I understand your question correct, you want to ensure that the month param is always two digits. This could be accomplished using regex:
[GET("{year:int:length(4)}-{month(^\d{2}$)}")] public ActionResult Days(int year, int month)
To make it a bit more readable to humans:
[GET("{year:int:length(4)}-{month}")] [RegexRouteConstraint("month", @"^\d{2}$")] public ActionResult Days(int year, int month)
Again, to add a little more "validation", your {month} regex should be:
{month}
0[1-9]|1[0-2]
This will force your month route to match one of the following: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12.
01
02
03
04
05
06
07
08
09
10
11
12
Sorry, something went wrong.
No branches or pull requests
Hi.
Is it possible to configure AttributeRouting so that some parameter would be formatted using specific format? For example, I have an action:
I want the
month
parameter to be always two-digit. How to achieve that with AttributeRouting?The text was updated successfully, but these errors were encountered: