cs-Panination

ylbtech-Unitity: cs-Panination

Pager.cs

IPagingOption.cs IPagedList.cs

PagingOption.cs PagedList.cs

PagingExtensions.cs

1.A,效果图返回顶部
1.B,源代码返回顶部

1.B.1,Pager.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
using Healthcare.Framework.Web.URL;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public class Pager
    {
        private ViewContext viewContext;
        private int currentPage;
        private int pageCount;
        private RouteValueDictionary pageLinkValueDictionary;

        private readonly int pageSize;
        private readonly int totalItemCount;
        private readonly RouteValueDictionary linkWithoutPageValuesDictionary;
        private readonly AjaxOptions ajaxOptions;
        private readonly string sortBy;
        private readonly bool? sortDescending;

        public Pager(ViewContext viewContext, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions)
        {
            this.viewContext = viewContext;
            this.pageSize = pageSize;
            this.currentPage = currentPage;
            this.totalItemCount = totalItemCount;
            this.linkWithoutPageValuesDictionary = valuesDictionary;
            this.ajaxOptions = ajaxOptions;
            this.ensureCollectionPageLinkValue();
        }

        public Pager(ViewContext viewContext, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions)
        {
            this.viewContext = viewContext;
            this.pageSize = pageSize;
            this.currentPage = currentPage;
            this.totalItemCount = totalItemCount;
            this.sortBy = sortBy;
            this.sortDescending = sortDescending;
            this.linkWithoutPageValuesDictionary = valuesDictionary;
            this.ajaxOptions = ajaxOptions;
            this.ensureCollectionPageLinkValue();
        }

        public HtmlString RenderHtml()
        {
            pageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize);
            if (pageCount == 0) pageCount = 1;
            const int nrOfPagesToDisplay = 4;

            if (pageCount < currentPage)
                currentPage = pageCount;

            var sb = new StringBuilder();

            // Previous
            sb.Append("<ul class=\"pagination pull-right\">");
            sb.Append(currentPage > 1 ? GeneratePageLink("«", 1, "first") : "<li class=\"first disabled\"><a>«</a></li>");
            sb.Append(currentPage > 1 ? GeneratePageLink("‹", currentPage - 1, "previous") : "<li class=\"previous disabled\"><a>‹</a></li>");

            var start = 1;
            var end = pageCount;

            if (pageCount > nrOfPagesToDisplay)
            {
                var middle = (int)Math.Ceiling(nrOfPagesToDisplay / 2d) - 1;
                var below = (currentPage - middle);
                var above = (currentPage + middle);

                if (below < 4)
                {
                    above = nrOfPagesToDisplay;
                    below = 1;
                }
                else if (above > (pageCount - 4))
                {
                    above = pageCount;
                    below = (pageCount - nrOfPagesToDisplay);
                }

                start = below;
                end = above;
            }

            if (start > 3)
            {
                sb.Append(GeneratePageLink("1", 1));
                sb.Append(GeneratePageLink("2", 2));
                sb.Append("<li class=\"disabled\"><a>...</a></li>");
            }

            for (var i = start; i <= end; i++)
            {
                if (i == currentPage || (currentPage <= 0 && i == 0))
                {
                    sb.AppendFormat("<li class=\"active\"><a>{0}</a></li>", i);
                }
                else
                {
                    sb.Append(GeneratePageLink(i.ToString(), i));
                }
            }
            //if (end < (pageCount - 5))
            //{
            //    sb.Append("<li class=\"disabled\"><a>...</a></li>");
            //    sb.Append(GeneratePageLink((pageCount - 3).ToString(), pageCount - 3));
            //    sb.Append(GeneratePageLink((pageCount - 2).ToString(), pageCount - 2));
            //    sb.Append(GeneratePageLink((pageCount - 1).ToString(), pageCount - 1));
            //    sb.Append(GeneratePageLink(pageCount.ToString(), pageCount));
            //}

            if (end  < pageCount)//后面还有其它页码
            {
                int tempmin = pageCount - 3;

                sb.Append("<li class=\"disabled\"><a>...</a></li>");
                for (int k = tempmin; k <= pageCount; k++)
                {
                    sb.Append(GeneratePageLink(k.ToString(), k));
                }
                //sb.Append(GeneratePageLink(pageCount.ToString(), pageCount));
            }

            // Next
            sb.Append(currentPage < pageCount ? GeneratePageLink("›", (currentPage + 1), "next") : "<li class=\"next disabled\"><a>›</a></li>");
            sb.Append(currentPage < pageCount ? GeneratePageLink("»", pageCount, "last") : "<li class=\"last disabled\"><a>»</a></li>");
            sb.Append("</ul>");

            return new HtmlString(sb.ToString());
        }

        private string GeneratePageLink(string linkText, int pageNumber, string classText = "")
        {
            if (pageLinkValueDictionary.ContainsKey("Page"))
            {
                pageLinkValueDictionary.Remove("Page");
            }

            pageLinkValueDictionary.Add("Page", pageNumber);

            // ‘Render‘ virtual path.
            var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);

            if (virtualPathForArea == null)
                return null;

            var stringBuilder = new StringBuilder("<li class=\"" + classText + "\"><a");

            if (ajaxOptions != null)
                foreach (var ajaxOption in ajaxOptions.ToUnobtrusiveHtmlAttributes())
                    stringBuilder.AppendFormat(" {0}=\"{1}\"", ajaxOption.Key, ajaxOption.Value);

            stringBuilder.AppendFormat(" href=\"{0}\">{1}</a></li>", virtualPathForArea.VirtualPath, linkText);

            return stringBuilder.ToString();
        }

        public HtmlString RenderGotoBaseUrl()
        {
            if (pageLinkValueDictionary.ContainsKey("Page"))
            {
                pageLinkValueDictionary.Remove("Page");
            }

            var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);

            return new HtmlString(virtualPathForArea.VirtualPath);
        }

        public HtmlString RenderSwitchPageSizeBaseUrl()
        {
            if (pageLinkValueDictionary.ContainsKey("PageSize"))
            {
                pageLinkValueDictionary.Remove("PageSize");
            }

            if (pageLinkValueDictionary.ContainsKey("Page"))
            {
                pageLinkValueDictionary.Remove("Page");
            }

            var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);

            return new HtmlString(virtualPathForArea.VirtualPath);
        }

        private void ensureCollectionPageLinkValue()
        {
            pageLinkValueDictionary = new RouteValueDictionary(linkWithoutPageValuesDictionary) { { "SortBy", sortBy }, { "SortDescending", sortDescending } };
            //{ { "Page", pageNumber }, { "PageSize", pageSize }, };

            Dictionary<string, string> dict = new Dictionary<string, string>();
            QueryStringHelper.ExtractQueryStringValuesFromUri(viewContext.HttpContext.Request.Url, ref dict);
            dict.Keys.ToList().ForEach(key =>
            {
                if (!pageLinkValueDictionary.ContainsKey(key))
                {
                    pageLinkValueDictionary.Add(key, dict[key]);
                }
            });

            // To be sure we get the right route, ensure the controller and action are specified.
            var routeDataValues = viewContext.RequestContext.RouteData.Values;
            routeDataValues.Keys.ToList().ForEach(key =>
            {
                if (!pageLinkValueDictionary.ContainsKey(key))
                {
                    pageLinkValueDictionary.Add(key, routeDataValues[key]);
                }
            });

        }
    }
}

1.B.2,IPagingOption.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public interface IPagingOption
    {
        int Page { get; set; }
        int PageSize { get; set; }
        int? TotalCount { get; set; }

        string SortBy { get; set; }
        bool? SortDescending { get; set; }
        string OrderByExpression { get; }

        RouteValueDictionary RouteValues { get; set; }
    }
}

1.B.3,IPagedList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public interface IPagedList<T> : IList<T>
    {
        int PageCount { get; }
        int TotalItemCount { get; }
        int PageIndex { get; }
        int PageNumber { get; }
        int PageSize { get; }
        bool HasPreviousPage { get; }
        bool HasNextPage { get; }
        bool IsFirstPage { get; }
        bool IsLastPage { get; }

        string SortBy { get; }
        bool? SortDescending { get; }

        RouteValueDictionary RouteValues { get; }
    }
}

1.B.4,PagingOption.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public class PagingOption : IPagingOption
    {
        public int Page { get; set; }
        public int PageSize { get; set; }
        public int? TotalCount { get; set; }
        public Int32? IsPagination { get; set; }
        public string ActionName { get; set; }
        public string SortBy { get; set; }
        public bool? SortDescending { get; set; }

        public bool ShowSummary { get; set; }
        public bool ShowGoto { get; set; }
        public bool ShowPageSize { get; set; }

        public PagingOption()
        {
            TotalCount = 0;
            PageSize = 10;
            Page = 1;
        }

        public RouteValueDictionary RouteValues { get; set; }

        public string OrderByExpression
        {
            get
            {
                return this.SortDescending.HasValue && this.SortDescending.Value ? this.SortBy + " desc" : this.SortBy + " asc";
            }
        }

        public int PageTotal
        {
            get
            {
                if (TotalCount == null)
                {
                    return (int)Math.Ceiling(0 / (double)PageSize);
                }
                return (int)Math.Ceiling(TotalCount.Value / (double)PageSize);

            }
        }
    }
}

1.B.5,PagedList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public class PagedList<T> : List<T>, IPagedList<T>
    {
        public PagedList(IEnumerable<T> source, IPagingOption option)
            : this(source.AsQueryable(), option)
        {
        }

        public PagedList(IQueryable<T> source, IPagingOption option)
        {
            if (option == null)
                throw new ArgumentOutOfRangeException("PagingOption", "Value can not be null.");
            if (option.Page < 0)
                throw new ArgumentOutOfRangeException("index", "Value must be greater than 0.");
            if (option.PageSize < 1)
                throw new ArgumentOutOfRangeException("pageSize", "Value must be greater than 1.");

            if (source == null)
                source = new List<T>().AsQueryable();
            var realTotalCount = source.Count();

            PageSize = option.PageSize;
            PageIndex = option.Page;
            RouteValues = option.RouteValues;
            TotalItemCount = option.TotalCount.HasValue ? option.TotalCount.Value : realTotalCount;
            PageCount = TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)PageSize) : 0;

            SortBy = option.SortBy;
            SortDescending = option.SortDescending;
            if (!string.IsNullOrEmpty(option.SortBy))
                source = source.OrderBy(option.OrderByExpression);

            HasPreviousPage = (PageIndex > 0);
            HasNextPage = (PageIndex < (PageCount - 1));
            IsFirstPage = (PageIndex <= 0);
            IsLastPage = (PageIndex >= (PageCount - 1));

            if (TotalItemCount <= 0)
                return;

            var realTotalPages = (int)Math.Ceiling(realTotalCount / (double)PageSize);

            if (realTotalCount < TotalItemCount && realTotalPages <= PageIndex)
                AddRange(source.Skip((realTotalPages - 1) * PageSize).Take(PageSize));
            else
                AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
        }

        #region IPagedList Members

        public int PageCount { get; private set; }
        public int TotalItemCount { get; private set; }
        public int PageIndex { get; private set; }
        public int PageNumber { get { return PageIndex + 1; } }
        public int PageSize { get; private set; }
        public bool HasPreviousPage { get; private set; }
        public bool HasNextPage { get; private set; }
        public bool IsFirstPage { get; private set; }
        public bool IsLastPage { get; private set; }
        public string SortBy { get; private set; }
        public bool? SortDescending { get; private set; }
        public RouteValueDictionary RouteValues { get; set; }
        #endregion
    }
}

1.B.6,PagingExtensions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace Healthcare.Framework.Web.Mvc.Pagination
{
    public static class PagingExtensions
    {
        #region AjaxHelper extensions

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, null, ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, actionName, null, ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string actionName, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, actionName, null, ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, object values, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, new RouteValueDictionary(values), ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string actionName, object values, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, null, actionName, new RouteValueDictionary(values), ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions)
        {
            return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, valuesDictionary, ajaxOptions);
        }

        public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions)
        {
            if (valuesDictionary == null)
            {
                valuesDictionary = new RouteValueDictionary();
            }
            if (actionName != null)
            {
                if (valuesDictionary.ContainsKey("action"))
                {
                    throw new ArgumentException("The valuesDictionary already contains an action.", "actionName");
                }
                valuesDictionary.Add("action", actionName);
            }
            var pager = new Pager(ajaxHelper.ViewContext, pageSize, currentPage, totalItemCount, sortBy, sortDescending, valuesDictionary, ajaxOptions);
            return pager.RenderHtml();
        }

        #endregion

        #region HtmlHelper extensions

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, null);
        }

        public static HtmlString PagerT(this HtmlHelper htmlHelper, PagingOption options)
        {
            if (options == null)
                return new HtmlString("");

            if (options.RouteValues == null)
            {
                options.RouteValues = new RouteValueDictionary();
            }

            var pager = new PagerT(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);
            return pager.RenderHtml();
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, null, null);
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, actionName, null);
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, new RouteValueDictionary(values));
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName, object values)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, null, actionName, new RouteValueDictionary(values));
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, valuesDictionary);
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, actionName, null);
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, RouteValueDictionary valuesDictionary)
        {
            if (valuesDictionary == null)
            {
                valuesDictionary = new RouteValueDictionary();
            }
            if (actionName != null)
            {
                if (valuesDictionary.ContainsKey("action"))
                {
                    throw new ArgumentException("The valuesDictionary already contains an action.", "actionName");
                }
                valuesDictionary.Add("action", actionName);
            }
            var pager = new Pager(htmlHelper.ViewContext, pageSize, currentPage, totalItemCount, sortBy, sortDescending, valuesDictionary, null);
            return pager.RenderHtml();
        }

        public static HtmlString Pager(this HtmlHelper htmlHelper, PagingOption options)
        {
            if (options == null)
                return new HtmlString("");

            if (options.RouteValues == null)
            {
                options.RouteValues = new RouteValueDictionary();
            }

            var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);
            return pager.RenderHtml();
        }

        public static HtmlString PagerGotoURL(this HtmlHelper htmlHelper, PagingOption options)
        {
            if (options == null)
                return new HtmlString("");

            if (options.RouteValues == null)
            {
                options.RouteValues = new RouteValueDictionary();
            }

            var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);
            return pager.RenderGotoBaseUrl();
        }

        public static HtmlString PagerGotoURL(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values = null)
        {
            PagingOption options = new PagingOption()
            {
                Page = 1,
                PageSize = pageSize,
                TotalCount = totalItemCount,
                RouteValues = new RouteValueDictionary(values)
            };
            return PagerGotoURL(htmlHelper, options);
        }

        public static HtmlString PagerSwitchPageSizeBaseUrl(this HtmlHelper htmlHelper, PagingOption options)
        {
            if (options == null)
                return new HtmlString("");

            if (options.RouteValues == null)
            {
                options.RouteValues = new RouteValueDictionary();
            }

            var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);
            return pager.RenderSwitchPageSizeBaseUrl();
        }

        public static HtmlString PagerSwitchPageSizeBaseUrl(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values = null)
        {
            PagingOption options = new PagingOption()
            {
                Page = 1,
                PageSize = pageSize,
                TotalCount = totalItemCount,
                RouteValues = new RouteValueDictionary(values)
            };
            return PagerSwitchPageSizeBaseUrl(htmlHelper, options);
        }

        #endregion

        #region ActionLink extensions

        public static HtmlString ActionLink<T>(this AjaxHelper ajaxHelper, string name, string actionName, IPagedList<T> model, AjaxOptions ajaxOptions)
        {
            var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;
            var routeValues = new RouteValueDictionary();
            routeValues.Add("SortBy", name);
            routeValues.Add("SortDescending", sortDescending);

            if (model.RouteValues != null)
            {
                foreach (var r in model.RouteValues)
                {
                    routeValues.Add(r.Key, r.Value);
                }
            }

            IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();

            var css = "";
            if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name))
            {
                if (model.SortDescending.HasValue && model.SortDescending.Value)
                    css = "sort-desc";
                else
                    css = "sort-asc";
            }
            else
                css = "sort-off";
            htmlAttributes.Add("class", css);

            return ajaxHelper.ActionLink(name, actionName, routeValues, ajaxOptions, htmlAttributes);
        }

        public static HtmlString ActionLink<T>(this AjaxHelper ajaxHelper, string label, string name, string actionName, IPagedList<T> model, AjaxOptions ajaxOptions)
        {
            var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;
            var routeValues = new RouteValueDictionary();
            routeValues.Add("SortBy", name);
            routeValues.Add("SortDescending", sortDescending);

            if (model.RouteValues != null)
            {
                foreach (var r in model.RouteValues)
                {
                    routeValues.Add(r.Key, r.Value);
                }
            }

            IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();

            var css = "";
            if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name))
            {
                if (model.SortDescending.HasValue && model.SortDescending.Value)
                    css = "sort-desc";
                else
                    css = "sort-asc";
            }
            else
                css = "sort-off";
            htmlAttributes.Add("class", css);

            return ajaxHelper.ActionLink(label, actionName, routeValues, ajaxOptions, htmlAttributes);
        }

        public static HtmlString ActionLink<T>(this HtmlHelper htmlHelper, string name, string actionName, IPagedList<T> model)
        {
            var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;
            var routeValues = new { SortBy = name, SortDescending = sortDescending };

            var css = "";
            if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name))
            {
                if (model.SortDescending.HasValue && model.SortDescending.Value)
                    css = "sort-desc";
                else
                    css = "sort-asc";
            }
            else
                css = "sort-off";
            var htmlAttributes = new { @class = css };
            return htmlHelper.ActionLink(name, actionName, routeValues, htmlAttributes);
        }

        #endregion

        #region IQueryable<T> extensions

        public static IPagedList<T> ToPagedList<T>(this IQueryable<T> source, IPagingOption option)
        {
            return new PagedList<T>(source, option);
        }

        #endregion

        #region IEnumerable<T> extensions

        public static IPagedList<T> ToPagedList<T>(this IEnumerable<T> source, IPagingOption option)
        {
            return new PagedList<T>(source, option);
        }

        #endregion
    }
}

1.B.7,

1.C,下载地址返回顶部
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
时间: 2024-08-07 04:34:13

cs-Panination的相关文章

CS文件类头注释

1.修改unity生成CS文件的模板(模板位置:Unity\Editor\Data\Resources\ScriptTemplates 文件名:81-C# Script-NewBehaviourScript.cs) 本人将模板修改为如下图(红框内的内容) 备注:在"#"之间的为可替换的参数 2.修改模板可替换参数,在工程项目Asset文件夹在创建Editor文件 在文件夹下添加AddFileHeadComment.cs文件 内容如下 参数内容根据个人需求修改

CS 和 BS 的区别和优缺点

bs是浏览器(browser)和服务器(server) cs是静态客户端程序(client)和服务器(server) 区别在于,虽然同样是通过一个程序连接到服务器进行网络通讯,但是bs结构的,客户端运行在浏览器里,比如你看百度,就是通过浏览器.还有一些bs结构的应用,比如中国电信,以及一些电子商务平台.用bs结构的好处是,不必专门开发一个客户端界面,可用asp,php,jsp等比较快速开发web应用的程序开发. cs结构的,要做一个客户端.网络游戏基本上大多是cs结构,比如你玩传奇,要专门开个传

微软SQLHelper.cs类 中文版

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Xml; using System.Collections; namespace LiuYanBanT { public class SqlHelper

AssemblyInfo.cs文件详解

一.前言 .net工程的Properties文件夹下自动生成一个名为AssemblyInfo.cs的文件,一般情况下我们很少直接改动该文件.但我们实际上通过另一个形式操作该文件.那就是通过在鼠标右键点击项目的属性进入“应用程序”->“程序集信息”,然后修改信息. 二.作用 通过特性(Attribute)来设置程序集(dll文件)的常规信息,供查看或作为配置信息供程序内部使用. 三.详解 // 程序集标题 [assembly:AssemblyTitle("程序集标题")] // 程

全局程序集GlobalAssemblyInfo.cs进行版本控制(引)

原文出自:http://blog.csdn.net/oyi319/article/details/5753311 1.全局程序集GlobalAssemblyInfo.cs 我们编写的一个解决方案,通常会包含多个项目,而每个项目都有单独的程序集信息AssemblyInfo.cs.但是,你会发现一个问题,这些AssemblyInfo.cs当中有一部分在重复的,若能把它们提取出来放入一个单一文件中,修改AssemblyInfo中的诸如产品名.产品版本.版本等信息会变得轻松.那么,这个程序集信息文件,我

【141030】CS结构的VC++远程控制程序源代码

CS结构的VC++远程控制程序源代码,类似于pcAnywhere的程序,程序分为主服务端和主控端.主控端也就是客户端,由用户发送指令到服务端后来控制受控计算机.因为服务端是安装在受控机上的,其程序原理与著名的远程控制软件PcAnywhere非常相似,只是只完成了基本功能,有兴趣的可自己扩展程序吧. 客户端: 服务端: 完整源码下载地址:点击下载

《CS:APP》 chapter 6 The Memory Hierarchy笔记

The Memory Hierarchy 6.1 Storage Technologies The earliest IBM PCs didn't even have a hard disk. 让我惊奇的是早期的IBM直接没有硬盘... 6.1.1 Random-Access Memory Random-access memory(RAM) comes in two varieties- static anddynamic . Static RAM (SRAM) is faster and si

CS游戏2--三次杀人机会,警察不能杀人

#coding=utf-8 import randomimport time ''' 本文章主要目主要有三个,1,随机增加5个系统人物,所有的都是随机产生的,2,人物角色如果是警察,则不能杀死警察,3,有三次机会杀死敌方 涉及的知识点有,随机数的产生,字典的存储和遍历 ''' list_kill=[0,1,1,1]list_name=range(10)dir_weapen={"AK47":2000,"匕首":500,"小手枪":1000}dir_

Atitit 软件架构方法的进化与演进cs bs soa roa &#160;msa&#160; attilax总结

Atitit 软件架构方法的进化与演进cs bs soa roa  msa  attilax总结 1.1. 软件体系架构是沿着单机到 CS 架构,再到 BS 的三层架构甚至多层架构逐步发展过来的,关于多层架构 1 1.2. 主进化路线Cs>> bs >>  SOA>>MSA(微服务架构1 1.3. 1 1.4. 面向资源体系架构(ROA)1 1.4.1. 管道和过滤器风格(数据流风格)2 1.5. 数据抽象与面向对象风格(调用/返回风格)2 1.6. 基于事件的隐式调用

用csc命令行手动编译cs文件

一般初学c#时,用记事本写代码,然后用命令行执行csc命令行可以编译cs文件.方法有两种 1:配置环境,一劳永逸 一般来说在C:\Windows\Microsoft.NET\Framework\v4.0.30319; 右键点击"计算机"--"属性"--"高级系统设置"--"环境变量"--"系统变量",找到变量Path      将Path中加上路径:C:/WINDOWS/Microsoft.NET/Fram