Skip to content
New issue

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

URL generation parameter format #273

Open
uksus70 opened this issue Oct 10, 2013 · 1 comment
Open

URL generation parameter format #273

uksus70 opened this issue Oct 10, 2013 · 1 comment

Comments

@uksus70
Copy link

uksus70 commented Oct 10, 2013

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?

@Kordonme
Copy link

Kordonme commented Feb 7, 2014

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants