我有一个 asp.net mvc 应用程序,其路由类似于:
routes.MapRoute("Blog",
"{controller}/{action}/{year}/{month}/{day}/{friendlyName}",
new { controller = "Blog", action = "Index", id = "", friendlyName="" },
new { controller = @"[^\.]*",
year = @"\d{4}",
month = @"\d{2}",
day = @"\d{2}" }
);
我的控制器操作方法签名如下所示:
public ActionResult Detail(int year, int month, int day, string friendlyName)
{ // Implementation... }
在我看来,我正在做类似的事情:
<%= Html.ActionLink<BlogController>(item => item.Detail(blog.PostedOn.Year, blog.PostedOn.Month, blog.PostedOn.Day, blog.Slug), blog.Title) %>
虽然使用 ActionLink 生成的 url 有效,但它使用查询字符串变量而不是 URL 重写。
例如,它将产生 /blog/detail/my-slug?year=2008&month=7&day=5 而不是 /blog/detail/2008/07/05/my-slug
有没有办法让 ActionLink 的通用版本正确填充整数值,以便 url 按预期显示?
谢谢
吉姆