【发布时间】:2010-11-16 16:11:23
【问题描述】:
谁能帮助我?我正在 ASP.NET MVC 中做一些测试。
我想将漂亮的 URL 实现为 stackoverflow.com 路由系统。
例如: stackoverflow.com/questions/1074/asp-mvc domain.com/id/title
这是我的代码:
- 在 Global.asax 中
routes.MapRoute(null,
"posts/{PostId}/{Title}",
new { controller = "Posts", action = "Details", post = (string)null },
new { PostId = @"\d+", Title = @"([A-Za-z0-9-]+)" }
);
- 在视图中:
<%= Html.ActionLink(Model.Title, "Details", new { Model.PostID, Model.Title})%>
通过这些代码,我得到了网址:http://localhost:53171/posts/Details?PostID=5&Title=Test-title
谁能给我建议?
非常感谢。
【问题讨论】:
标签: asp.net-mvc