码迷,mamicode.com
首页 > Web开发 > 详细

asp.net MVC: PagedList + View Model

时间:2015-11-11 16:39:13      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

asp.net MVC: PagedList + View Model

标签:

原文地址:http://blog.csdn.net/jameszhou/article/details/49763937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!