首页 > Web开发 > 详细

基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)

时间:2015-11-24 12:55:46      阅读:521      评论:0      收藏:0      [点我收藏+]

使用方法:
先把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 style="text-align:center;">
        @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

基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)

原文:http://www.cnblogs.com/gaocong/p/4991174.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!