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>

    效果:

  • 相关阅读:
    生产者-消费者模型-线程安全队列Queue
    多线程简单案例
    cloudstack 用admin 账号创建虚拟机只是提示insufficient resource
    什么是工厂函数?Python 中工厂函数怎么理解?(转)
    rsync + mysql + gzip + --single-transaction
    Python中获取异常(try Exception)信息
    ansible copy 模块 changed false 没有变化
    _mysql.c:29:20: error: Python.h: No such file or directory
    常用网址
    Android 中常见控件的介绍和使用
  • 原文地址:https://www.cnblogs.com/Zingu/p/14718452.html
Copyright © 2011-2022 走看看