我的路由系统可以传递没有日期或日期的页码。
routes.MapRoute(
name: "ArticlesArchiveFilter",
url: "Article/Archive/{searchDate}/{pageNumber}",
defaults: new { controller = "Article", action = "Archive", searchDate = UrlParameter.Optional, pageNumber = "" }
);
routes.MapRoute(
name: "ArticlesArchiveBasic",
url: "Article/Archive/{pageNumber}",
defaults: new { controller = "Article", action = "Archive", pageNumber = "" }
);
我的问题是,在传递网址时,日期时间和网页编号的网址路由有效但不能没有日期时间,因为网页编号始终默认为1。
我的控制器看起来像这样......
public ActionResult Archive(DateTime? searchDate, int pageNumber = 1)
{
ArticleListViewModel model = new ArticleListViewModel();
model = new ArticlePageManager().Filter(searchDate, pageNumber: pageNumber).MapToList();
return View(model);
}
任何人都知道如何解决这个问题?
答案 0 :(得分:1)
尝试更改您的路线。
routes.MapRoute(
name: "ArticlesArchiveFilter",
url: "Article/Archive/{pageNumber}/{searchDate}",
defaults: new { controller = "Article", action = "Archive", searchDate = UrlParameter.Optional, pageNumber = "" }
);