Mvc Pager 分页

来源:互联网 发布:windows xp iso下载 编辑:程序博客网 时间:2024/06/14 06:34

1.引用 MvcPager.dll
2.Controller

public ActionResult Index(int? id = 1){    Ch7wZzyjs.BLL.Zzy_School BllSchool = new Ch7wZzyjs.BLL.Zzy_School();    List<Ch7wZzyjs.Model.Zzy_School> userList = new List<Ch7wZzyjs.Model.Zzy_School>();    //int totalCount = 0;    int totalCount = 10;    int pageIndex = id ?? 1;    DataSet ds = BllSchool.getHotSchool();    DataTable dt = ds.Tables[0];    //需要写一个分页查询方法,并且返回总页数    userList = BllSchool.DataTableToList2(dt);    PagedList<Ch7wZzyjs.Model.Zzy_School> mPage = userList.AsQueryable().ToPagedList(pageIndex, 2);    mPage.TotalItemCount = totalCount;    mPage.CurrentPageIndex = (int)(id ?? 1);    return View(mPage);}

3.View

@{    ViewBag.Title = "Index";}@using Webdiyer.WebControls.Mvc;@using Ch7wZzyjs.Model;@model PagedList<Zzy_School>@using Webdiyer.WebControls.Mvc;@{    Layout = null;}<!DOCTYPE html><html><head>    <title>List</title></head><body>    @foreach (Zzy_School user in Model)    {        @user.AdPosID<span>---</span>@user.SchoolName<span>---</span>        @Html.ActionLink("Edit", "Edit", new { id = user.AreaID }) <span>---</span>        @Html.ActionLink("Details", "Details", new { id = user.AreaID }) <span>---</span>        @Html.ActionLink("Delete", "Delete", new { id = user.AreaID })<span>---</span>        <br />    }    <br />    <br />    @Html.Pager(Model, new PagerOptions{    PageIndexParameterName = "id",    ShowPageIndexBox = true,    FirstPageText = "首页",    PrevPageText = "上一页",    NextPageText = "下一页",    LastPageText = "末页",    PageIndexBoxType = PageIndexBoxType.TextBox,    PageIndexBoxWrapperFormatString = "请输入页数{0}",    GoButtonText = "转到"})    <br />    >>分页 共有 @Model.TotalItemCount 篇留言 @Model.CurrentPageIndex/@Model.TotalPageCount</body></html>

参考博客:
https://www.cnblogs.com/iamlilinfeng/archive/2013/03/11/2951460.html

原创粉丝点击