正如标题所说......
我有一条路线(列出的第一条路线),如下所示:
routes.MapRoute(
"TopicRoute", // Route name
"forums/{forumSlug}/{topicSlug}", // URL with parameters
new { controller = "Forums", action = "Topic"} // Parameter defaults
);
我可以浏览:
/forums/my-forum/my-topic
并且页面加载正常。然而,我有一个看起来像的Html.ActionLink:
@Html.ActionLink(item.Title, "Topic", new { forumSlug ="my-forum", topicSlug = "my-topic" })
它不会为我生成正确的链接语法?它会生成:
<a href="">My Topic</a>
答案 0 :(得分:3)
不要忘记控制器:
@Html.ActionLink(item.Title, "Topic",
new { forumSlug ="my-forum", topicSlug = "my-topic", controller = "Forums" })
或使用指定的路线链接:
@Html.RouteLink(item.Title, "TopicRoute",
new { forumSlug = "my-forum", topicSlug = "my-topic" })