PagedListPager pass additional model data

余生长醉 提交于 2019-12-07 04:51:39

问题


I have the following model:

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

ShowAllClients is a checkbox that I'll use to further filter the list of clients returned from the server.

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

Here is my pager:

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

Both the pager and checkbox are on the same form.

The problem that I'm having is that when I change page on the pager control, the checkbox is always set to false. This is happening because in the Index action, ShowAllClients is set to false.

How would I preserve the checkbox data when changing pages?


回答1:


I got this to work with the following:

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



回答2:


Best solution if found so far is:

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

And yes it works.



来源:https://stackoverflow.com/questions/14356152/pagedlistpager-pass-additional-model-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!