Reputation:
I have created a new route like the following:
routes.MapRoute(
"BlogYMD",
"blog/date/{year}/{month}/{day}",
new { controller = "Blog", action = "Date", year = "2009", month="01", day="01" });
The view simply returns a concatenation of year, month and day. This works fine for URL's like:
http://localhost/blog/date/2009/01/01
However if I enter this URL:
http://localhost/blog/date/2009
I would expect the default values for month and day to be passed to the date method. However they aren't, all the parameters on the method come through as null.
Am I missing something obvious?
Upvotes: 2
Views: 949
Reputation: 4945
The order in which you declare routes is important. You want your custom route(s) declared before the default.
Upvotes: 2
Reputation: 126587
You don't show the rest of your routes, but I suspect you have another route above this one in your global.asax.CS (for example, the default route) which matches the second URL.
Upvotes: 2