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
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 vNext or .NET vNext?
- 详解 ASP.NET异步
- 利用JasperReport+iReport进行Web报表开发
- Struts2整合JasperReport
- Asp.net或C#使用word模板生成替换后的Word和pdf文档-总结
- Dnsmasp详解
- JasperReport学习笔记8-JasperReport和Hibernate,Struts的整合
- JasperReport学习笔记7-导出成其它格式(pdf,xls,html)
- JasperReport学习笔记6-JRXML的标签
- JasperReport学习笔记5-其它数据生成动态的报表(WEB)
- asp+AJAX 用escape解决url传递中文乱码的问题
- JasperReport学习笔记4-查询数据库生成动态的报表(WEB)
- JasperReport学习笔记3-在浏览器生成PDF文件
- 在GridView中设置每个单元格的数据
- JasperReport学习笔记2-创建简单的报表例子
- JasperReport学习笔记1-了解JasperReport
- Asp.net 学习宏观总结
- Linq与lamda写法对比
- asp.net mvc中匿名类dynamic
- 配置asp.net 2.0的项目到IIS7