【发布时间】:2013-03-11 19:49:43
【问题描述】:
我有一个呈现新闻列表的视图,因为我有一个 href 标记,我需要调用一个 Detail 方法并将新闻 id 传递给它,现在我的 url 中有一个这样的查询字符串 News/Details?id=x... 但我需要类似 News/Details/Category/Title-of-something 的东西,一个带有新闻类别、名称且没有 id 的友好 url
这是我的操作,它有效,但我得到了那个查询字符串
foreach (var item in Model)
{
<a href='@Url.Action("Details", "News", new { id = item.newsId, category = item.categoryName, name = item.newsName })' title=""> Read More </a>
}
我正在尝试使用 Url.RouteUrl 之类的东西
routes.MapRoute(
name: "Details",
url: "{controller}/{action}/{id}/{category}/{newsName}",
defaults: new { controller = "News", action = "Details"}
);
但它永远不会进入详细信息操作结果,而且我需要传递 id 参数来显示一些新闻详细信息,但我不想在友好的 url 中显示它。我真的很困惑如何实现它。提前致谢
【问题讨论】:
-
路由可能被其他路由覆盖。因此,复制此路线并将其移至顶部。我的意思是,将这条路线放在另一条路线的顶部
标签: asp.net-mvc asp.net-mvc-3 friendly-url