我有这个路由图:
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
我想念什么?
更新
我以这种方式在默认之前移动了 MapRoute:
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”已成为默认操作!