0
我有我要求我的生成URL作为MVC博客URL路由
/2013/10/custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
我已经看到了很多问题来实现它&我的问题可能有重复的可能性。像: -
asp-net-mvc-framework-part-2-url-routing
custome-mvc-url-rout-to-display-mixture-of-id-and-urlslug
等等
我已经如下实现它: -
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
我在做什么错?请有人指出它。
Thiks!
你可以发布你的路线?特别是路线的顺序(Post和Default)。我认为路线应该是'routes.MapRoute( “Post”, “blog/post/{year}/{month}/{title}”, new {controller =“Blog”,action =“Post”} );',否则这些段可能会与默认路由冲突。 – shakib