views:

289

answers:

2

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?

+1  A: 

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.

Craig Stuntz
Cheers for the answer.
+1  A: 

The order in which you declare routes is important. You want your custom route(s) declared before the default.

Jon Freeland