Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PagedListPager pass additional model data

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?

like image 537
woggles Avatar asked Jan 16 '13 10:01

woggles


1 Answers

I got this to work with the following:

 @Html.PagedListPager(Model.Clients, page => Url.Action("Index", new PagedClientViewModel { Page = page, ShowAllClients = Model.ShowAllClients }))
like image 193
woggles Avatar answered Sep 28 '22 23:09

woggles