I have a route defined like this:
routes.MapRoute("Date", "Date/{year}/{month}/{day}",
new { controller = "Date", action = "Index", year = UrlParameter.Optional,
month = UrlParameter.Optional, day = UrlParameter.Optional });
So it has 3 optional parameters, year, month and day. It works fine in routing a GET request, all the following work fine:
http://myhost/myapp/Date
http://myhost/myapp/Date/2011
http://myhost/myapp/Date/2011/8
http://myhost/myapp/Date/2011/8/17
Generating links using RouteUrl works in all cases except one.
For example, the case where I want a link including the year and a month works fine. I use the following (simplified) code in my view:
string linkUrl = Url.RouteUrl("Date",
new { controller = "Date", year = 2011, month = 8 },
Request.Url.Scheme);
But the case where only the year is defined does not work and returns null, the code is:
string linkUrl = Url.RouteUrl("Date",
new { controller = "Date", year = 2011 },
Request.Url.Scheme);
So it all looks correct to me. Any clue what I'm doing wrong, or how to debug this further.