Jim*_*rts 5 c# asp.net-mvc routing
我有一个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}" }
);
Run Code Online (Sandbox Code Playgroud)
我的控制器操作方法签名如下所示:
public ActionResult Detail(int year, int month, int day, string friendlyName)
{ // Implementation... }
Run Code Online (Sandbox Code Playgroud)
在我看来,我做的事情如下:
<%= Html.ActionLink<BlogController>(item => item.Detail(blog.PostedOn.Year, blog.PostedOn.Month, blog.PostedOn.Day, blog.Slug), blog.Title) %>
Run Code Online (Sandbox Code Playgroud)
虽然使用ActionLink生成的url有效,但它使用查询字符串变量而不是URL重写.
例如,它会生成/ blog/detail/my-slug?year = 2008&month = 7&day = 5而不是/ blog/detail/2008/07/05/my-slug
有没有办法让ActionLink的通用版本正确填充整数值,以便url按预期出现?
谢谢
吉姆
归档时间: |
|
查看次数: |
2816 次 |
最近记录: |