我有一个标有特定“主题”的谜题列表。思考关于 stackoverflow 标记为某些类别的问题。
我正在尝试设置我的路线,以便它像这样工作:
http://www.wikipediamaze.com/puzzles/themed/ 电影 http://www.wikipediamaze.com/puzzles/themed/Movies,Another-Theme,And-Yet-Another-One
我的路线设置如下:
routes.MapRoute(
"wiki",
"wiki/{topic}",
new {controller = "game", action = "continue", topic = ""}
);
routes.MapRoute(
"UserDisplay",
"{controller}/{id}/{userName}",
new {controller = "users", action = "display", userName=""},
new { id = @"\d+" }
);
routes.MapRoute(
"ThemedPuzzles",
"puzzles/themed/{themes}",
new { controller = "puzzles", action = "ThemedPuzzles", themes = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Home", action = "Index", id = ""} // Parameter defaults
);
我的控制器看起来像这样:
public ActionResult ThemedPuzzles(string themes, PuzzleSortType? sortType, int? page, int? pageSize)
{
//Logic goes here
}
我在视图中的操作链接调用如下所示:
<ul>
<%foreach (var theme in Model.Themes)
{ %>
<li><%=Html.ActionLink(theme, "themed", new {controller = "puzzles", themes = theme})%></li>
<% } %>
</ul>
但是我遇到的问题是:
生成的链接如下所示:
http://www.wikipediamaze.com/puzzles/themed?themes=MyThemeNameHere
要添加到此问题,控制器操作上的“主题”参数始终为空。它从不将查询字符串参数转换为控制器操作参数。但是,如果我手动导航到
http://www.wikipediamaze.com/puzzles/themed/MyThemeNameHere http://www.wikipediamaze.com/puzzles/themed/MyThemeNameHere,Another-ThemeName
一切正常。我错过了什么?
提前致谢!