你的位置:首页 > ASP.net教程

[ASP.net教程]基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)


使用方法:
先把mvcpager.dll引用加入mvc项目 下载路径在本文末尾

前台代码

前台:@{  Layout = null;}@using Webdiyer.WebControls.Mvc@model PagedList<string><!DOCTYPE html><html><head>  <meta name="viewport" content="width=device-width" />  <title>Index</title>    <link href="~/Content/css_pager.css" rel="stylesheet" />  </head><body>  <div>    @foreach (var item in Model)    {      @item<br />      }  </div>  <div >    @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })<!-- @class 可为pagination或pager 样式可自行修改样式表-->  </div></body></html>

 后台代码

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Webdiyer.WebControls.Mvc;namespace MvcApplication6.Controllers{  public class HomeController : Controller  {    //    // GET: /Home/    public ActionResult Index(int pageIndex=1, int pageSize=2)    {      List<string> list = new List<string>(){       "a",       "b",       "c",       "d"      };      return View(list.ToPagedList(pageIndex, pageSize));    }  }}

@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })

 样式更改:class为pager或pagination

如图:

下载路径: http://files.cnblogs.com/files/gaocong/MvcPager.rar