I've defined the following route for a simple blog.
routes.MapRoute(
"Blog",
"blog/{year}/{month}/{day}",
new { controller = "Blog", action = "Index" },
new { year = @"\d{4}", month = @"\d{2}", day = @"\d{2}" }
);
The url should be able "hackable" to accomplish the following:
- http://abc.com/blog/2010 -> shows all posts in 2010
- http://abc.com/blog/2010/01 -> shows all posts in January 2010
- http://abc.com/blog/2010/01/25 -> shows all posts in January 25th, 2010
I have created a controller which handles this action quite nicely. However I am having trouble creating links in my views using Url.Action()
.
For example this...
var d = new DateTime(2010, 1, 25);
Url.Action("Index", "Blog", new { year=d.Year, month=d.Month, day=d.Day} );
...generates a url like that looks like this:
I would rather like it to generate a url that looks like the urls in the list above.
Is there any way I can use Url.Action()
or Html.ActionLink()
to generate urls in the format I desire?