我有三个看起来像这样的路线:
all.html
all/page-{numpage}.html
all/page-{numpage}-limit-{limit}.html.
前两个工作正常 - 这意味着在我的控制器中,如果没有给出,我将获得 numpage 或 1 的值:
public ViewResult All(int numpage = 1, int limit = 10) {}
numpage 是我在地址栏中输入的任何内容
第三条路线根本不起作用-好像我去了第一条路线(all.html),所以它的值等于1,限制是10-默认值。但是,当我转到 all/page-4.html?limit=3 时,我得到了正确的值。我究竟做错了什么?:D
还有一件事——我动态地创建我的路由,所以注册它们的代码看起来像这样(rcache 返回正确的路由列表):
List<Tuple<Dictionary<string, string>, string, string, string>> routes = rcache.GetRoutes();
foreach (var route in routes) {
foreach (KeyValuePair<string, string> kvp in route.Item1) {
context.MapRoute(
route.Item4,
kvp.Value,
new { controller = route.Item2, action = route.Item3, id = UrlParameter.Optional, name = UrlParameter.Optional, numpage = UrlParameter.Optional, limit = UrlParameter.Optional }
);
}
}