zoukankan      html  css  js  c++  java
  • VS

    BootstrapPagination.cshtml

    @model PaginationModel
    <div class="pagination">
    	<ul>
    		@foreach (var link in Model.PaginationLinks)
      {
    			@BuildLink(link)
    		}
    	</ul>
    </div>
    
    @helper BuildLink(PaginationLink link)
        {
        var liBuilder = new TagBuilder("li");
        if (link.IsCurrent)
        {
            liBuilder.MergeAttribute("class", "active");
        }
        if (!link.Active)
        {
            liBuilder.MergeAttribute("class", "disabled");
        }
    
        var aBuilder = new TagBuilder("a");
        if (link.PageIndex != null) {
            aBuilder.MergeAttribute("data-page", link.PageIndex.Value.ToString());
        }
        if (link.Url == null)
        {
            //aBuilder.MergeAttribute("href", "#");
        }
        else
        {
            aBuilder.MergeAttribute("href", link.Url);
            aBuilder.AddCssClass("paging");
        }
        if (link.DisplayText == "«")
        {
            aBuilder.SetInnerText("←");
        }
        else if (link.DisplayText == "»")
        {
            aBuilder.SetInnerText("→");
        }
        else
        {
            aBuilder.SetInnerText(link.DisplayText);
        }
        liBuilder.InnerHtml = aBuilder.ToString();
    	
    	@Html.Raw(liBuilder.ToString())
    }
    

    PaginatedList.cs

       public class PaginatedList<T> : List<T> {
            public int Offset { get; private set; }
            public int PageIndex { get; private set; }
            public int PageSize { get; private set; }
            public int TotalCount { get; private set; }
            public int TotalPages { get; private set; }
    
            /// <summary>
            /// For manually paing.
            /// </summary>
            /// <param name="source">The result of current page</param>
            /// <param name="totalCount"></param>
            /// <param name="pageIndex"></param>
            /// <param name="pageSize"></param>
            public PaginatedList(IEnumerable<T> source, int totalCount, int pageIndex, int pageSize)
            {
                Offset = pageIndex * pageSize;
                PageIndex = pageIndex;
                PageSize = pageSize;
                TotalCount = totalCount;
                TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
    
                this.AddRange(source);
            }
    
            public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize) {
                Offset = pageIndex * pageSize;
                PageIndex = pageIndex;
                PageSize = pageSize;
                TotalCount = source.Count();
                TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
    
                this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
            }
    
            public PaginatedList(IQueryable<T> source, int pageSize, int? offset = null, int? pageIndex = null) {
                if (offset != null) {
                    Offset = offset.Value;
                    PageIndex = (int)Math.Ceiling((decimal)Offset / pageSize);
                } else if (pageIndex != null) {
                    Offset = pageIndex.Value * pageSize;
                    PageIndex = pageIndex.Value;
                } else {
                    //offset = null and pageIndex = null
                    throw new ArgumentNullException("offset and pageIndex");
                }
                PageSize = pageSize;
                TotalCount = source.Count();
                TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
    
                this.AddRange(source.Skip(Offset).Take(PageSize));
            }
    
            public bool HasPreviousPage {
                get {
                    return (Offset > 0);
                }
            }
    
            public bool HasNextPage {
                get {
                    return (Offset + PageSize < TotalCount);
                }
            }
    
        }

    public PaginatedList<classname> classnameList { get; set; }

    classnameList = new PaginatedList<EventCallDetail>(classList, count, (pageIndex > 0) ? pageIndex - 1 : 0, PageSize);

     @Html.Pager(PageSize, PageIndex + 1, classnameList.TotalCount).Options(o => o.DisplayTemplate("BootstrapPagination"))

  • 相关阅读:
    安徽省2016“京胜杯”程序设计大赛_B_阵前第一功
    安徽省2016“京胜杯”程序设计大赛_A_砝码称重
    NYOJ_23_取石子(一)
    akoj-1369 贪吃蛇
    akoj-1369 贪吃蛇
    2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
    2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
    LeetCode() Repeated DNA Sequences 看的非常的过瘾!
    LeetCode()Substring with Concatenation of All Words 为什么我的超时呢?找不到原因了!!!
    LeetCode() Valid Anagram 有问题!!!
  • 原文地址:https://www.cnblogs.com/sui84/p/7018397.html
Copyright © 2011-2022 走看看