I have my requirement to generate my URL as
/2013/10/custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
I have seen many questions to achieve it & my question may have possibility of Duplicate.. Like:-
asp-net-mvc-framework-part-2-url-routing
custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
etc...
I have achieved it as follows:-
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Post",
"{year}/{month}/{title}",
new { controller = "Blog", action = "Post" }
);
and my Hyperlink which would generate this would be :-
@Html.ActionLink("continue...", "post", "blog",
new {
year = Model.PostedOn.Year,
month = Model.PostedOn.Month,
day = Model.PostedOn.Day,
title = Model.UrlSlug
}, new { title = "continue..." })
My MVC Controller being :-
public ViewResult Post(int year, int month, string title)
{}
But the issue over here is , I am getting my URL as :
http://localhost:2083/blog/post?Year=2013&Month=10&Day=9&title=best_practices_in_programming
and not like :-
http://localhost:2083/blog/post/2013/10/best_practices_in_programming
What am I doing wrong ? Please can someone point it.
Thnks!