zoukankan      html  css  js  c++  java
  • C# 自定义Html分页

     public class CustomPager
        {
    
            /// <summary>
            /// 每页行数
            /// </summary>
            public int PageSize { get; set; }
            /// <summary>
            /// 总行数
            /// </summary>
            public int TotalCount { get; set; }
            /// <summary>
            /// 总页码
            /// </summary>
            public int pageCount { get; set; }
    
            /// <summary>
            /// 最多显示页码数
            /// </summary>
            public int MaxPageCount { get; set; }        
            /// <summary>
            /// 当前页码数
            /// </summary>
            public int PageIndex { get; set; }
            /// <summary>
            /// 当前最小页码
            /// </summary>
            public int StartPage { get; set; }
            /// <summary>
            /// 当前最大页码
            /// </summary>
            public int EndPage { get; set; }
            /// <summary>
            /// 页码连接
            /// </summary>
            public string PageUrl { get; set; } = "/list_{pn}";          
    
            public CustomPager()
            {
                MaxPageCount = 10;
                PageSize = 10;
            }
            public string GetPage()
            {
                pageCount = (int)Math.Ceiling(TotalCount * 1.0 / PageSize);
                StartPage = Math.Max(1, PageIndex-MaxPageCount / 2);
                EndPage = Math.Min(pageCount, StartPage+ MaxPageCount-1);
    
                 StringBuilder strb = new StringBuilder();
                strb.AppendLine("<ul >");
                for (int i = StartPage; i <= EndPage; i++)
                {
                    if (i==PageIndex)
                    {
                        strb.AppendLine($"<li  style='color:red; display: inline;' class='active'>{i}</li>");
                    }
                    else
                    {
                        //strb.AppendLine($"<li><a href='{PageUrl.Replace("{pn}",i.ToString())}'>{i}</li>");
                        strb.AppendLine($"<li style='display: inline;'>{i}</li>");
                    }
                }
    
                strb.AppendLine("</ul>");  
                return strb.ToString();
    
            }
        }

    Control:

     public class DefaultController : Controller
        {
            // GET: Default
            public ActionResult Index()
            {
                return View();
            }
        }

    View:

    @using MVC04.Pages; @*对应CustomPager 命名空间*@
     
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
        <script type="text/javascript"> 
        </script>
    </head>
    <body>
        <div> 
            @{ 
                CustomPager cp = new CustomPager();
                cp.pageCount = 10;
                cp.MaxPageCount = 10;
                cp.PageIndex = 11;
                cp.TotalCount = 901;
                cp.PageSize = 50; 
            }
            @Html.Raw(cp.GetPage())
    
            <button onclick="addpage()">增加</button>
        </div>
    </body>
    </html>

    效果:

  • 相关阅读:
    O365(世纪互联)SharePoint 之调查列表简单介绍
    O365(世纪互联)SharePoint 之使用列表库发布新闻
    O365(世纪互联)SharePoint 之使用Designer报错
    SharePoint 2016 配置向导报错
    sharePoint 2016 弃用和删除的功能
    O365(世纪互联)SharePoint 之站点个性化
    数据分析与数据挖掘概述
    scrapy框架系列 (5) Spider类
    scrapy框架系列 (4) Scrapy Shell
    scrapy框架系列 (3) Item Pipline
  • 原文地址:https://www.cnblogs.com/Zingu/p/14718452.html
Copyright © 2011-2022 走看看