【发布时间】:2009-08-18 16:29:11
【问题描述】:
我有一个带有特定“主题”标签的谜题列表。思考关于带有特定类别标签的 stackoverflow 问题。
我正在尝试设置我的路线,以便它像这样工作:
http://www.wikipediamaze.com/puzzles/themed/Movies 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
一切正常。我错过了什么?
提前致谢!
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing