您的位置:首页 > 编程语言 > ASP

asp.net MVC: PagedList + View Model

2015-11-10 19:18 906 查看
To pass view model with PagedList:

1. Controller action must use HttpGet and use View Model as action parameter

public ActionResult Index(UserIndexModel model)
2. In 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 on View Model like below:

public IPagedList PagingMetaData { get; set; }

3. In View use 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)
参考: 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: