MVC分页实现

10 篇文章 0 订阅

很实用的MVC分页,提供给大家学习,有什么更好的方法可以留言,大家一起探讨。

添加分页类  PagerHelper.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Reflection;
using System.Web;
using System.Web.Compilation;
using System.IO;
using System.Collections.Specialized;
using System.Linq.Expressions;
using System.Data;
using System.Text.RegularExpressions;

namespace System.Web.Mvc
{
    public enum BarStyle
    {
        yahoo, digg, meneame, flickr, sabrosus, scott, quotes, black, black2, grayr, yellow, jogger, starcraft2, tres, megas512, technorati, youtube, msdn, badoo, viciao, yahoo2, green_black
    }
    public static class PagerBarExtension
    {

        public static string RenderPagerBar(this HtmlHelper html, int page, int total)
        {
            return RenderPagerBar(html, page, total, BarStyle.technorati);
        }

        public static string RenderPagerBar(this HtmlHelper html, int page, int total, BarStyle style)
        {
            return RenderPagerBar(html, page, total, style, total);
        }

        public static string RenderPagerBar(this HtmlHelper html, int page, int total, BarStyle style, int show)
        {
            if (total == 1)
            {
                return "";
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                string _path = html.ViewContext.HttpContext.Request.Path;
                sb.Append("<div class=/"");
                sb.Append(style.ToString());
                sb.Append("/" >");

                string queryString = html.ViewContext.HttpContext.Request.QueryString.ToString();
                if (queryString.IndexOf("page=") < 0)
                {
                    queryString += "&page=" + page;
                }
                Regex re = new Regex(@"page=/d+", RegexOptions.IgnoreCase);
                string result = re.Replace(queryString, "page={0}");

                if (page != 1)
                {
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"第一页/">{1}</a></span>", _path + "?" + string.Format(result, 1), "<<");
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"上一页/">{1}</a></span>", _path + "?" + string.Format(result, page - 1), "<");
                }
                if (page > (show + 1))
                {
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"前" + (show + 1) + "页/">{1}</a></span>", _path + "?" + string.Format(result, page - (show + 1)), "..");

                }
                for (int i = page - show; i <= page + show; i++)
                {
                    if (i == page)
                    {
                        sb.AppendFormat("<span class=/"current/">{0}</span>", i);
                    }
                    else
                    {
                        if (i > 0 & i <= total)
                        {
                            sb.AppendFormat("<span><a href=/"{0}/">{1}</a></span>", _path + "?" + string.Format(result, i), i);
                        }
                    }
                }
                if (page < (total - (show)))
                {
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"后" + (show + 1) + "页/">{1}</a></span>", _path + "?" + string.Format(result, page + (show + 1)), "..");

                }
                if (page < total)
                {
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"下一页/">{1}</a></span>", _path + "?" + string.Format(result, page + 1), ">");
                    sb.AppendFormat("<span><a href=/"{0}/" title=/"最后一页/">{1}</a></span>", _path + "?" + string.Format(result, total), ">>");

                }
                sb.AppendFormat("<span class=/"current/">共{1}页</span>", page, total);
                sb.Append("</div>");
                return sb.ToString();
            }
        }
    }
}

 

样式文件  pagecss.css

 

DIV.digg A{border-right:#aad 1px solid; border-top:#aad 1px solid; border-left:#aad 1px solid; color:#009; border-bottom:#aad 1px solid; text-decoration:none; margin:2px; padding:2px 5px}

DIV.digg SPAN.current{border-right:#009 1px solid; border-top:#009 1px solid; font-weight:700; border-left:#009 1px solid; color:#fff; border-bottom:#009 1px solid; background-color:#009; margin:2px; padding:2px 5px}

DIV.yahoo A{border-right:#fff 1px solid; border-top:#fff 1px solid; border-left:#fff 1px solid; color:#009; border-bottom:#fff 1px solid; text-decoration:underline; margin:2px; padding:2px 5px}

DIV.yahoo A:active{border-right:#009 1px solid; border-top:#009 1px solid; border-left:#009 1px solid; color:red; border-bottom:#009 1px solid}

DIV.yahoo SPAN.current{border-right:#fff 1px solid; border-top:#fff 1px solid; font-weight:700; border-left:#fff 1px solid; color:#000; border-bottom:#fff 1px solid; background-color:#fff; margin:2px; padding:2px 5px}

DIV.meneame{font-size:80%; color:#ff6500; text-align:center; margin:3px; padding:3px}

DIV.meneame A{border-right:#ff9600 1px solid; background-position:50% bottom; border-top:#ff9600 1px solid; background-image:url(meneame.jpg); border-left:#ff9600 1px solid; color:#ff6500; margin-right:3px; border-bottom:#ff9600 1px solid; text-decoration:none; padding:5px 7px}

DIV.meneame A:hover{border-right:#ff9600 1px solid; border-top:#ff9600 1px solid; background-image:none; border-left:#ff9600 1px solid; color:#ff6500; border-bottom:#ff9600 1px solid; background-color:#ffc794}

DIV.meneame SPAN.current{border-right:#ff6500 1px solid; border-top:#ff6500 1px solid; font-weight:700; border-left:#ff6500 1px solid; color:#ff6500; margin-right:3px; border-bottom:#ff6500 1px solid; background-color:#ffbe94; padding:5px 7px}

DIV.meneame SPAN.disabled{border-right:#ffe3c6 1px solid; border-top:#ffe3c6 1px solid; border-left:#ffe3c6 1px solid; color:#ffe3c6; margin-right:3px; border-bottom:#ffe3c6 1px solid; padding:5px 7px}

DIV.flickr A{border-right:#dedfde 1px solid; background-position:50% bottom; border-top:#dedfde 1px solid; border-left:#dedfde 1px solid; color:#0061de; margin-right:3px; border-bottom:#dedfde 1px solid; text-decoration:none; padding:2px 6px}

DIV.flickr SPAN.current{font-weight:700; color:#ff0084; margin-right:3px; padding:2px 6px}

DIV.sabrosus A{border-right:#9aafe5 1px solid; border-top:#9aafe5 1px solid; border-left:#9aafe5 1px solid; color:#2e6ab1; margin-right:2px; border-bottom:#9aafe5 1px solid; text-decoration:none; padding:2px 5px}

DIV.sabrosus A:hover{border-right:#2b66a5 1px solid; border-top:#2b66a5 1px solid; border-left:#2b66a5 1px solid; color:#000; border-bottom:#2b66a5 1px solid; background-color:#FFFFE0}

DIV.sabrosus SPAN.current{border-right:navy 1px solid; border-top:navy 1px solid; font-weight:700; border-left:navy 1px solid; color:#fff; margin-right:2px; border-bottom:navy 1px solid; background-color:#2e6ab1; padding:2px 5px}

DIV.sabrosus SPAN.disabled{border-right:#929292 1px solid; border-top:#929292 1px solid; border-left:#929292 1px solid; color:#929292; margin-right:2px; border-bottom:#929292 1px solid; padding:2px 5px}

DIV.scott A{border-right:#ddd 1px solid; border-top:#ddd 1px solid; border-left:#ddd 1px solid; color:#88af3f; margin-right:2px; border-bottom:#ddd 1px solid; text-decoration:none; padding:2px 5px}

DIV.scott SPAN.current{border-right:#b2e05d 1px solid; border-top:#b2e05d 1px solid; font-weight:700; border-left:#b2e05d 1px solid; color:#fff; margin-right:2px; border-bottom:#b2e05d 1px solid; background-color:#b2e05d; padding:2px 5px}

DIV.quotes A{border-right:#ddd 1px solid; border-top:#ddd 1px solid; border-left:#ddd 1px solid; color:#aaa; margin-right:2px; border-bottom:#ddd 1px solid; text-decoration:none; padding:2px 5px}

DIV.quotes SPAN.current{border-right:#e0e0e0 1px solid; border-top:#e0e0e0 1px solid; font-weight:700; border-left:#e0e0e0 1px solid; color:#aaa; margin-right:2px; border-bottom:#e0e0e0 1px solid; background-color:#f0f0f0; padding:2px 5px}

DIV.black{font-size:80%; color:#a0a0a0; background-color:#000; text-align:center; margin:3px; padding:10px 3px}

DIV.black A{border-right:#909090 1px solid; background-position:50% bottom; border-top:#909090 1px solid; background-image:url(bar.gif); border-left:#909090 1px solid; color:silver; margin-right:3px; border-bottom:#909090 1px solid; text-decoration:none; padding:2px 5px}

DIV.black SPAN.current{border-right:#fff 1px solid; border-top:#fff 1px solid; font-weight:700; border-left:#fff 1px solid; color:#fff; margin-right:3px; border-bottom:#fff 1px solid; background-color:#606060; padding:2px 5px}

DIV.black SPAN.disabled{border-right:#606060 1px solid; border-top:#606060 1px solid; border-left:#606060 1px solid; color:gray; margin-right:3px; border-bottom:#606060 1px solid; padding:2px 5px}

DIV.black2 A{border-right:#000 1px solid; border-top:#000 1px solid; border-left:#000 1px solid; color:#000; border-bottom:#000 1px solid; text-decoration:none; margin:2px; padding:2px 5px}

DIV.black2 SPAN.current{border-right:#000 1px solid; border-top:#000 1px solid; font-weight:700; border-left:#000 1px solid; color:#fff; border-bottom:#000 1px solid; background-color:#000; margin:2px; padding:2px 5px}

DIV.black-red{font-size:11px; color:#fff; font-family:Tahoma,Arial,Helvetica,Sans-serif; background-color:#3e3e3e}

DIV.black-red A{color:#fff; background-color:#3e3e3e; text-decoration:none; margin:2px; padding:2px 5px}

DIV.black-red SPAN.current{font-weight:700; color:#fff; background-color:#313131; margin:2px; padding:2px 5px}

DIV.black-red SPAN.disabled{color:#868686; background-color:#3e3e3e; margin:2px; padding:2px 5px}

DIV.grayr{font-size:11px; font-family:Tahoma,Arial,Helvetica,Sans-serif; background-color:#c1c1c1; padding:2px}

DIV.grayr A{color:#000; background-color:#c1c1c1; text-decoration:none; margin:2px; padding:2px 5px}

DIV.grayr SPAN.current{font-weight:700; color:#303030; background-color:#fff; margin:2px; padding:2px 5px}

DIV.grayr SPAN.disabled{color:#797979; background-color:#c1c1c1; margin:2px; padding:2px 5px}

DIV.yellow A{border-right:#ccc 1px solid; border-top:#ccc 1px solid; border-left:#ccc 1px solid; color:#000; border-bottom:#ccc 1px solid; text-decoration:none; margin:2px; padding:2px 5px}

DIV.yellow SPAN.current{border-right:#d9d300 1px solid; border-top:#d9d300 1px solid; font-weight:700; border-left:#d9d300 1px solid; color:#fff; border-bottom:#d9d300 1px solid; background-color:#d9d300; margin:2px; padding:2px 5px}

DIV.jogger{font-family:"Lucida Sans Unicode","Lucida Grande",LucidaGrande,"Lucida Sans",Geneva,Verdana,sans-serif; margin:7px; padding:2px}

DIV.jogger A{color:#fff; background-color:#ee4e4e; text-decoration:none; margin:2px; padding:0.5em 0.64em 0.43em}

DIV.jogger SPAN.current{color:#6d643c; background-color:#f6efcc; margin:2px; padding:0.5em 0.64em 0.43em}

DIV.starcraft2{font-weight:700; font-size:13.5pt; color:#fff; font-family:Arial; background-color:#000; text-align:center; margin:3px; padding:3px}

DIV.starcraft2 A{color:#fa0; background-color:#000; text-decoration:none; margin:2px}

DIV.starcraft2 SPAN.current{font-weight:700; color:#fff; background-color:#000; margin:2px}

DIV.starcraft2 SPAN.disabled{color:#444; background-color:#000; margin:2px}

DIV.tres{font-weight:700; font-size:13.2pt; font-family:Arial,Helvetica,sans-serif; text-align:center; margin:3px; padding:7px}

DIV.tres A{border-right:#d9d300 2px solid; border-top:#d9d300 2px solid; border-left:#d9d300 2px solid; color:#fff; border-bottom:#d9d300 2px solid; background-color:#d90; text-decoration:none; margin:2px; padding:2px 5px}

DIV.tres SPAN.current{border-right:#fff 2px solid; border-top:#fff 2px solid; font-weight:700; border-left:#fff 2px solid; color:#000; border-bottom:#fff 2px solid; margin:2px; padding:2px 5px}

DIV.megas512 A{border-right:#dedfde 1px solid; background-position:50% bottom; border-top:#dedfde 1px solid; border-left:#dedfde 1px solid; color:#99210b; margin-right:3px; border-bottom:#dedfde 1px solid; text-decoration:none; padding:2px 6px}

DIV.megas512 SPAN.current{font-weight:700; color:#99210b; margin-right:3px; padding:2px 6px}

DIV.technorati A{border-right:#ccc 1px solid; background-position:50% bottom; border-top:#ccc 1px solid; font-weight:700; border-left:#ccc 1px solid; color:#4261de; margin-right:3px; border-bottom:#ccc 1px solid; text-decoration:none; padding:2px 6px}

DIV.youtube{border-top:#9c9a9c 1px dotted; font-size:13px; color:#313031; font-family:Arial,Helvetica,sans-serif; background-color:#cecfce; text-align:right; padding:4px 6px 4px 0}

DIV.youtube A{font-weight:700; color:#0030ce; text-decoration:underline; margin:0 1px; padding:1px 3px}

DIV.youtube SPAN.current{color:#000; background-color:#fff; padding:1px 2px}

DIV.msdn{font-size:13px; color:#313031; font-family:Verdana,Tahoma,Arial,Helvetica,Sans-Serif; background-color:#fff; text-align:right; padding:4px 6px 4px 0}

DIV.msdn A{border-right:#b7d8ee 1px solid; border-top:#b7d8ee 1px solid; border-left:#b7d8ee 1px solid; color:#0030ce; border-bottom:#b7d8ee 1px solid; text-decoration:none; margin:0 3px; padding:5px 6px 4px 5px}

DIV.msdn SPAN.current{border-right:#b7d8ee 1px solid; border-top:#b7d8ee 1px solid; font-weight:700; border-left:#b7d8ee 1px solid; color:#444; border-bottom:#b7d8ee 1px solid; background-color:#d2eaf6; margin:0 3px; padding:5px 6px 4px 5px}

DIV.badoo{font-size:13px; color:#48b9ef; font-family:Arial,Helvetica,sans-serif; background-color:#fff; text-align:center; padding:10px 0}

DIV.badoo A{border-right:#f0f0f0 2px solid; border-top:#f0f0f0 2px solid; border-left:#f0f0f0 2px solid; color:#48b9ef; border-bottom:#f0f0f0 2px solid; text-decoration:none; margin:0 2px; padding:2px 5px}

DIV.badoo A:hover{ background:#fff;}
DIV.badoo SPAN.current{border-right:#ff5a00 2px solid; border-top:#ff5a00 2px solid; font-weight:700; border-left:#ff5a00 2px solid; color:#fff; border-bottom:#ff5a00 2px solid; background-color:#ff6c16; padding:2px 5px}

.manu A{border-right:#eee 1px solid; border-top:#eee 1px solid; border-left:#eee 1px solid; color:#036cb4; border-bottom:#eee 1px solid; text-decoration:none; margin:2px; padding:2px 5px}

.manu .current{border-right:#036cb4 1px solid; border-top:#036cb4 1px solid; font-weight:700; border-left:#036cb4 1px solid; color:#fff; border-bottom:#036cb4 1px solid; background-color:#036cb4; margin:2px; padding:2px 5px}

DIV.green_black A, DIV.green_black A:visited{border-right:#2c2c2c 1px solid; border-top:#2c2c2c 1px solid; background:#2c2c2c url(/Content/images/image0.gif) 0 bottom; border-left:#2c2c2c 1px solid; color:#fff; margin-right:2px; border-bottom:#2c2c2c 1px solid; text-decoration:none; padding:2px 5px}

DIV.green_black A:hover, DIV.green_black A:active{border-right:#aad83e 1px solid; border-top:#aad83e 1px solid; background:url(/Content/images/image0.gif) #aad83e; border-left:#aad83e 1px solid; color:#fff; border-bottom:#aad83e 1px solid}

DIV.green_black SPAN.current{border-right:#aad83e 1px solid; border-top:#aad83e 1px solid; font-weight:700; background:url(/Content/images/image0.gif) #aad83e; border-left:#aad83e 1px solid; color:#fff; margin-right:2px; border-bottom:#aad83e 1px solid; padding:2px 5px}

DIV.viciao{margin-top:20px; margin-bottom:10px}

DIV.viciao A{border-right:#8db5d7 1px solid; border-top:#8db5d7 1px solid; border-left:#8db5d7 1px solid; color:#000; margin-right:2px; border-bottom:#8db5d7 1px solid; text-decoration:none; padding:2px 5px}

DIV.viciao SPAN.current{border-right:#e89954 1px solid; border-top:#e89954 1px solid; font-weight:700; border-left:#e89954 1px solid; color:#000; margin-right:2px; border-bottom:#e89954 1px solid; background-color:#ffca7d; padding:2px 5px}

DIV.viciao SPAN.disabled{border-right:#ccc 1px solid; border-top:#ccc 1px solid; border-left:#ccc 1px solid; color:#ccc; margin-right:2px; border-bottom:#ccc 1px solid; padding:2px 5px}

DIV.yahoo2{font-size:0.85em; font-family:Tahoma,Helvetica,sans-serif; text-align:center; margin:3px; padding:3px}

DIV.yahoo2 A{border-right:#ccdbe4 1px solid; background-position:50% bottom; border-top:#ccdbe4 1px solid; border-left:#ccdbe4 1px solid; color:#0061de; margin-right:3px; border-bottom:#ccdbe4 1px solid; text-decoration:none; padding:2px 8px}

DIV.yahoo2 A.next{border-right:#ccdbe4 2px solid; border-top:#ccdbe4 2px solid; border-left:#ccdbe4 2px solid; border-bottom:#ccdbe4 2px solid; margin:0 0 0 10px}

DIV.yahoo2 A.prev{border-right:#ccdbe4 2px solid; border-top:#ccdbe4 2px solid; border-left:#ccdbe4 2px solid; border-bottom:#ccdbe4 2px solid; margin:0 10px 0 0}

DIV.digg, DIV.yahoo, DIV.flickr, DIV.sabrosus, DIV.scott, DIV.quotes, DIV.megas512, DIV.technorati, .manu, DIV.green_black{text-align:center; margin:3px; padding:3px}

DIV.digg A:hover, DIV.digg A:active, DIV.yahoo A:hover{border-right:#009 1px solid; border-top:#009 1px solid; border-left:#009 1px solid; color:#000; border-bottom:#009 1px solid}

DIV.digg SPAN.disabled, DIV.yahoo SPAN.disabled, DIV.black2 SPAN.disabled, DIV.yellow SPAN.disabled, .manu .disabled{border-right:#eee 1px solid; border-top:#eee 1px solid; border-left:#eee 1px solid; color:#ddd; border-bottom:#eee 1px solid; margin:2px; padding:2px 5px}

DIV.meneame A:active, DIV.flickr A:hover{border-right:#000 1px solid; border-top:#000 1px solid; background-image:none; border-left:#000 1px solid; color:#fff; border-bottom:#000 1px solid; background-color:#0061de}

DIV.flickr SPAN.disabled, DIV.megas512 SPAN.disabled{color:#adaaad; margin-right:3px; padding:2px 6px}

DIV.pagination A:active, DIV.msdn A:hover{border-right:#b7d8ee 1px solid; border-top:#b7d8ee 1px solid; border-left:#b7d8ee 1px solid; color:#0066a7; border-bottom:#b7d8ee 1px solid; background-color:#d2eaf6}

DIV.scott A:hover, DIV.scott A:active{border-right:#85bd1e 1px solid; border-top:#85bd1e 1px solid; border-left:#85bd1e 1px solid; color:#638425; border-bottom:#85bd1e 1px solid; background-color:#f1ffd6}

DIV.scott SPAN.disabled, DIV.quotes SPAN.disabled, DIV.green_black SPAN.disabled{border-right:#f3f3f3 1px solid; border-top:#f3f3f3 1px solid; border-left:#f3f3f3 1px solid; color:#ccc; margin-right:2px; border-bottom:#f3f3f3 1px solid; padding:2px 5px}

DIV.quotes A:hover, DIV.quotes A:active{border-right:#a0a0a0 1px solid; border-top:#a0a0a0 1px solid; border-left:#a0a0a0 1px solid; margin-right:2px; border-bottom:#a0a0a0 1px solid; padding:2px 5px}

DIV.black A:hover, DIV.black A:active{border-right:#f0f0f0 1px solid; border-top:#f0f0f0 1px solid; background-image:url(invbar.gif); border-left:#f0f0f0 1px solid; color:#fff; border-bottom:#f0f0f0 1px solid; background-color:#404040}

DIV.black2, DIV.yellow{text-align:center; margin:3px; padding:7px}

DIV.black2 A:hover, DIV.black2 A:active{border-right:#000 1px solid; border-top:#000 1px solid; border-left:#000 1px solid; color:#fff; border-bottom:#000 1px solid; background-color:#000}

DIV.black-red A:hover, DIV.black-red A:active{color:#fff; background-color:#ec5210}

DIV.grayr A:hover, DIV.grayr A:active{color:#000; background-color:#9ff}

DIV.yellow A:hover, DIV.yellow A:active{border-right:#f0f0f0 1px solid; border-top:#f0f0f0 1px solid; border-left:#f0f0f0 1px solid; color:#000; border-bottom:#f0f0f0 1px solid}

DIV.jogger A:hover, DIV.jogger A:active{color:#fff; background-color:#de1818; margin:2px; padding:0.5em 0.64em 0.43em}

DIV.jogger SPAN.disabled, DIV.tres SPAN.disabled, DIV.technorati SPAN.disabled, DIV.youtube SPAN.disabled, DIV.msdn SPAN.disabled, DIV.badoo SPAN.disabled, DIV.yahoo2 SPAN.disabled{display:none}

DIV.starcraft2 A:hover, DIV.starcraft2 A:active{color:#fff; background-color:#000}

DIV.tres A:hover, DIV.tres A:active{border-right:#ff0 2px solid; border-top:#ff0 2px solid; border-left:#ff0 2px solid; color:#000; border-bottom:#ff0 2px solid; background-color:#ff0}

DIV.megas512 A:hover, DIV.megas512 A:active{border-right:#000 1px solid; border-top:#000 1px solid; background-image:none; border-left:#000 1px solid; color:#fff; border-bottom:#000 1px solid; background-color:#777}

DIV.technorati A:hover, DIV.technorati A:active{background-image:none; color:#fff; background-color:#4261df}

DIV.technorati SPAN.current, DIV.yahoo2 SPAN.current{font-weight:700; color:#000; margin-right:3px; padding:2px 6px}

DIV.badoo A:hover, DIV.badoo A:active{border-right:#ff5a00 2px solid; border-top:#ff5a00 2px solid; border-left:#ff5a00 2px solid; color:#ff5a00; border-bottom:#ff5a00 2px solid}

.manu A:hover, .manu A:active{border-right:#999 1px solid; border-top:#999 1px solid; border-left:#999 1px solid; color:#666; border-bottom:#999 1px solid}

DIV.viciao A:hover, DIV.viciao A:active{border-right:red 1px solid; border-top:red 1px solid; border-left:red 1px solid; margin-right:2px; border-bottom:red 1px solid; padding:2px 5px}

DIV.yahoo2 A:hover, DIV.yahoo2 A:active{border-right:#2b55af 1px solid; border-top:#2b55af 1px solid; background-image:none; border-left:#2b55af 1px solid; color:#fff; border-bottom:#2b55af 1px solid; background-color:#3666d4}

DIV.yahoo2 A.next:hover, DIV.yahoo2 A.prev:hover{border-right:#2b55af 2px solid; border-top:#2b55af 2px solid; border-left:#2b55af 2px solid; border-bottom:#2b55af 2px solid}

 

Controller:

 public ActionResult UserList(int? page,int? pageIndex)    
        {
            UsersBLL bll = new UsersBLL();
            int _page = page?? 1;
            int pageSize = 1;                                        //每页显示条数
            ViewData["PageIndex"] = _page;                           //当前页
            int TotalCount = UsersBLL.CountRow("");                  //总数量

            if (TotalCount % pageSize == 0)
            {
                int aa = TotalCount / pageSize;
                ViewData["TotalPage"] = TotalCount / pageSize;       //总页数
            }
            else
            {
                int aa = TotalCount / pageSize + 1;
                ViewData["TotalPage"] = TotalCount / pageSize+1;     //总页数
            }
            if (!Request.IsAjaxRequest())
            {
                MVCDemoModel.UsersModel[] userlist = UsersBLL.GetAllUser(pageSize, _page).ToArray<MVCDemoModel.UsersModel>();     //取得用户的列表  返回的是List集合,但是接收时为数组,将数组在转换为List集合
                ViewData["UserList"] = userlist.ToList<MVCDemoModel.UsersModel>();
            }
            return View();
        }

 

View页面:

<%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]))%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.badoo )%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.badoo,3 )%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.black,4 )%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.digg,4 )%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.flickr,3 )%>
    <%= Html.RenderPagerBar(Convert.ToInt32(ViewData["PageIndex"]),Convert.ToInt32(ViewData["TotalPage"]),BarStyle.grayr,3 )%>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值