5

我有以下模型:

  public class PagedClientViewModel
    {
        public int? Page { get; set; }
        public PagedList.PagedList<ClientViewModel> Clients { get; set; }               
        public bool ShowAllClients { get; set; }
    }

ShowAllClients 是一个复选框,我将使用它来进一步过滤从服务器返回的客户端列表。

 @Html.CheckBoxFor(model => model.ShowAllClients, new { id = "ShowAllClientsCheckbox" })

这是我的寻呼机:

@Html.PagedListPager(Model.Clients, page => Url.Action("Index", new { Page = page }), PagedListRenderOptions.DefaultPlusFirstAndLast)

寻呼机和复选框都在同一个表单上。

我遇到的问题是,当我在寻呼机控件上更改页面时,复选框始终设置为 false。发生这种情况是因为在 Index 操作中,ShowAllClients 设置为 false。

更改页面时如何保留复选框数据?

4

3 回答 3

8

我得到这个与以下工作:

 @Html.PagedListPager(Model.Clients, page => Url.Action("Index", new PagedClientViewModel { Page = page, ShowAllClients = Model.ShowAllClients }))
于 2013-01-24T11:21:12.697 回答
0

迄今为止找到的最佳解决方案是:

@Html.PagedListPager(Model.Clients, page => Url.Action("Index", new { Page = page, param1="",param2="" }), PagedListRenderOptions.DefaultPlusFirstAndLast)

是的,它有效。

于 2019-04-11T07:16:34.757 回答
0

在我的例子中,模型是 PagedList.IPagedList。接下来,我使用了一个“SearchModel”,它存储在 ViewBag 中,因此可以轻松传递。我需要更新的是页码。

@Html.PagedListPager(Model, page =>
{
    ViewBag.SearchModel.Page = page;
    return Url.Action("Index", "Search", ViewBag.SearchModel);
})
于 2021-01-23T09:54:30.520 回答