mvc 分页PagedList简单使用
2016-07-18 13:59
274 查看
1.nuget下载PagedList包
2.PageListHelper类:
3.创建一个部分页_PagedListPartial.cshtml
4.Index页面调用:
2.PageListHelper类:
using PagedList; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ClothMvcApp.Helper { public class PageListHelper<T> { public IPagedList<T> PageList { get; set; } public string Controller { get; set; } public string Action { get; set; } public string Key { get; set; } } }
3.创建一个部分页_PagedListPartial.cshtml
<div class="page-box"> @{ int pageIndex = 1; int pageSize = 1; if (Model.PageList != null) { pageIndex = Model.PageList.PageNumber; pageSize = Model.PageList.PageSize; <span>共<span style="color:orange;font-weight:bold;">@Model.PageList.TotalItemCount</span>条 共<span style="color: orange; font-weight: bold;">@Model.PageList.PageCount</span>页</span> <a href="@Url.Action(Model.Action, Model.Controller, new { pageIndex = 1,pageSize=Model.PageList.PageSize,key=Model.Key })">首页</a> if (Model.PageList.HasPreviousPage) { <a href="@Url.Action(Model.Action, Model.Controller, new { pageIndex = (Model.PageList.PageNumber - 1), pageSize = Model.PageList.PageSize, key = Model.Key })">上一页</a> } <select onchange="changePageSize(this)" style="width:70px;"> @{ for (int i = 1; i <= 10; i++) { <option value="@(i*5)" @(Model.PageList.PageSize == i*5 ? "selected" : "")>@(i*5)</option> } } </select> if (Model.PageList.HasNextPage) { <a href="@Url.Action(Model.Action, Model.Controller, new { pageIndex = (Model.PageList.PageNumber + 1), pageSize = Model.PageList.PageSize, key = Model.Key })">下一页</a> } <a href="@Url.Action(Model.Action, Model.Controller, new { pageIndex = Model.PageList.PageCount, pageSize = Model.PageList.PageSize, key = Model.Key })">末页</a> } } </div> <script type="text/javascript"> function changePageSize(obj) { var pageSize = obj.value; window.location = "/Admin/@Model.Controller/@Model.Action?pageIndex=@pageIndex&pageSize="+pageSize+"&key=@Model.Key" } function search() { var key = document.getElementById("key").value; window.location = "/Admin/@Model.Controller/@Model.Action?pageIndex=1&pageSize=@pageSize&key=" + key; } </script>
4.Index页面调用:
@using ClothMvcApp.EF; @using ClothMvcApp.Helper; @{ Layout = null; var list = ViewBag.data as PagedList.IPagedList<ClothMvcApp.EF.Product>; }
@Html.Partial("_PagedListPartial", new PageListHelper<ClothMvcApp.EF.Product>() { Controller = "Cloth", Action = "Index", Key = ViewBag.key, PageList = list })
相关文章推荐
- phpStudy for Linux (lnmp+lamp一键安装包)
- Java:Map与HashMap,Hashtable,HashSet比较
- Android 跨进程通信学习标签
- php学习之路
- 国内一些大公司(阿里巴巴、腾讯、百度、网易、豆瓣等)的开源项目
- 通过带有泛型类型的父类获取实体类型
- liunx 系统注意危险的十大命令---谨慎使用
- Embedded Linux S3C2440 environment setup
- 滤波基础知识
- 过滤器
- 几种常见架构模式
- 仿制网站被抄袭的几个有效解决的方法
- js判断是否为PC端
- android wear下载
- Delphi 自动检测U盘插入、拔出及获取U盘盘符!
- delphi 获取USB口拔出和插入的状态
- jQuery radio取值,checkbox取值,select取值
- 正则匹配<{$vcode}>变量
- android学笔记 AsynTask异步向服务器Post图片
- list里面包含list的解析方法