To pass view model with Pagedlist:
1. Controller action must use HttpGet and use View Model as action parameter
Public ActionResultIndex (Userindexmodelmodel)
2. The action return the view model with Pagingmetadata
model. Pagingmetadata =New staticpagedlist<Userindexitem> (model. Users, model. Page.value, Default_page_size, total);
return model;
Pagingmetadata is defined in View Model like below:
Public ipagedlistPagingmetadata {Get; Set; }
3. In view with the Pager like below to pass data needed back to action by View model:
@Html. Pagedlistpager (New staticpagedlist<report.areas.tis.models.Userindexitem> (model.users, Model.pagingmetadata),
page = url.action ("Index", new routevaluedictionary () {
{ "page", page},
{ "filtername", model.filtername},
{ "Filterdatebegin", Model.filterdatebegin},
{ "filterdateend", model.filterdateend},
{ "Filtersiteid", Model.filtersiteid},
{ "filterposition", model.filterposition},
{ "filterupdated",false}}),
pagedlistrenderoptions. Classic)
Reference:
Http://stackoverflow.com/questions/14258212/mvc-posting-ipagedlist
Http://czetsuya-tech.blogspot.co.id/2011/05/mvc3-dynamic-search-paging-using.html#.VkHD8TahfIU
Https://github.com/TroyGoode/PagedList
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ASP. Mvc:pagedlist + View Model