PagedListPager传递其他模型数据

问题描述 投票:5回答:2

我有以下型号:

  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。

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

c# asp.net-mvc pagedlist
2个回答
8
投票

我得到了以下工作:

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

0
投票

到目前为止找到的最佳解决方案是:

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

是的,它的确有效。

© www.soinside.com 2019 - 2024. All rights reserved.