当我有一个路由需要多个参数时,我在使用Html.ActionLink时遇到了问题。例如,假设我的Global.asax文件中定义了以下路由:
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Tagging",
"{controller}.mvc/{action}/{tags}",
new { controller = "Products", action = "Index", tags = "" }
);
routes.MapRoute(
"SlugsAfterId",
"{controller}.mvc/{action}/{id}/{slug}",
new { controller = "Products", action = "Browse", id = "", slug = "" }
);
前两个路由正常工作,但当我尝试使用以下命令创建指向第三个路由的操作链接时:
<%= Html.ActionLink(Html.Encode(product.Name), "Details", new { id = product.ProductId, slug = Html.Encode(product.Name) }) %>
我最终得到了一个类似site-root/Details/1?slug=url-slug的网址,而我希望这个网址更像site-root/Details/1/url-slug
有没有人能看到我哪里出了问题?
https://stackoverflow.com/questions/734249
复制相似问题