我有一张表,上面有条目,每页有 10 个条目,总页数约为 130。
如何在同一视图上处理操作,同时仍保留内存中的分页...
@using (Html.BeginForm())
{
<label>All Logs since :</label> <input id="startDate" name="startDate" class="datepicker" type="text" value="@Model.option.startDate.Value.ToString("dddd, dd MMMM yyyy")" />
<input type="submit" />
}
提交后,我希望表格根据开始日期进行过滤。但是如果用户点击一个页面链接,我需要这个研究结果来覆盖我视图中的默认设置。这是我的控制器中的操作:
[HttpGet]
public ActionResult Index(int? id)
{
MainViewModel model = new MainViewModel();
model.option = new LogOption();
model.option.numberOfResultPerPage = 10;
model.option.startDate = (method to set default date)
model.option.startPageIndex = id ?? 1;
*** call to service with the model.options as filter and set my table's column info and retreive the logs total in a custom class ( model.listing ) ***
model.totalPage = model.listing.TotalPages;
return View(model);
现在当用户提交一个新的日期时,我会做同样的事情,但有一点不同,即将默认日期设置为类似的东西:
[HttpPost]
public ActionResult Index(LogOption mod)
{
model.option.startDate = mod.startDate;
}
问题是,如果在修改 startDate 过滤器之后,如果用户单击以从我的表中更改页面,则再次调用 get 操作,我不知道如何处理对原始默认设置的覆盖。我可以以更清洁的方式做到这一点而不必在会话中设置信息吗?
我想我需要将模型与获取信息一起传递,但我无法做到。
[HttpPOST]
public ActionResult Index(MainViewModel mod, int? id)
{
}
但是当我这样做时,我的 MainViewModel 总是为空,所以除了在会话中保存它之外,我不知道如何获取这两个信息,但我被告知要避免这种情况,并且可以以其他方式进行