我有這個路由映射:MVC 3 URL參數渲染
routes.MapRoute(
"ViewNews",
"{controller}/{action}/{id}/{title}",
new { controller = "Home", action = "NewsDetail", id = "", title = "" }
);
,這ActionLink的在我看來:
@Html.ActionLink(Model.Title, "NewsDetail", new { id = Model.Id, title = Url.ToFriendlyUrl(Model.Title) })
我希望它呈現這樣的事情:
http://localhost:49327/Home/NewsDetail/1/news-title
代替它呈現:
http://localhost:49327/Home/NewsDetail/1?title=news-title
我想念什麼?
更新
我以這種方式默認前移到圖路線:
routes.MapRoute(
"ViewNews",
"{controller}/{action}/{id}/{title}",
new { controller = "Home", action = "NewsDetail", id = "", title = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
但現在當我要求的初始URL:
http://localhost:49327/Home
我立刻被重新導向至:
http://localhost:49327/Home/NewsDetail/1/news-title
「NewsDetail」已成爲默認操作!
這個答案可能會幫助你,@達林的答案:http://stackoverflow.com/questions/734249/asp-net-mvc-url-routing-with-multiple-route-values – Niklas