我有我的要求将我的 URL 生成为
/2013/10/custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
我已经看到了很多问题来实现它&我的问题可能有重复的可能性..比如:-
asp-net-mvc-framework-part-2-url-路由
custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
ETC...
我已经实现了如下: -
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" }
);
我的超链接会生成这个:-
@Html.ActionLink("continue...", "post", "blog",
new {
year = Model.PostedOn.Year,
month = Model.PostedOn.Month,
day = Model.PostedOn.Day,
title = Model.UrlSlug
}, new { title = "continue..." })
我的 MVC 控制器是:-
public ViewResult Post(int year, int month, string title)
{}
但这里的问题是,我的网址是:
http://localhost:2083/blog/post?Year=2013&Month=10&Day=9&title=best_practices_in_programming
不喜欢:-
http://localhost:2083/blog/post/2013/10/best_practices_in_programming
我究竟做错了什么 ?请有人指出它。
谢谢!