当我的路由需要多个参数时,我遇到了 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的 URL,而我希望 URL 更像[site-root]/Details/1/url-slug
谁能看到我哪里出错了?