zoukankan      html  css  js  c++  java
  • 关于C#传给视图的字符串带有Html转义字符的处理

    public class PageBarHelper//分页类
        {
            public static string GetPageBar(string requestHref,int totalCount,int pageIndex,int pageSize)
            {
                //初始化pageSize,如果为0,默认为5
                pageSize = pageSize == 0 ? 5 : pageSize;
                pageIndex = pageIndex == 0 ? 1 : pageIndex;
    
                //计算总页数
                int pageCount = Convert.ToInt32(Math.Ceiling((double)(totalCount / pageSize)));
                //构建输出字符串
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<div id='pageBar'>");
                //判断pageCount是否足够分页,足够分页时
                if (pageCount > 1)
                {
                    if (pageIndex!=1)  //如果当前页不是第一页,显示首页标识
                    {
                        sb.AppendFormat("<a href='{0}?pageIndex=1&&pageSize={1}'>首  页", requestHref, pageSize);
                    }
                    sb.Append("  ");
                    if (pageIndex>1)  //如果当前页大于1,显示上一页标识
                    {
                        sb.AppendFormat("<a href='{0}?pageIndex={1}&&pageSize={2}'>上一页</a>"
                            , requestHref, pageIndex - 1, pageSize);
                    }
                    sb.Append("  ");
                    if (pageIndex!=pageCount) //如果当前页不是最后一页,显示下一页标识
                    {
                        sb.AppendFormat("<a href='{0}?pageIndex={1}&&pageSize={2}'>下一页</a>"
                            , requestHref, pageIndex + 1, pageSize);
                        sb.AppendFormat("<a href='{0}?pageIndex={1}&&pageSize={2}'>末  页</a>"
                            , requestHref, pageCount, pageSize);
                    }    
                    sb.Append("        ");
    
                }
                sb.AppendFormat("第{0}页/共{1}页", pageIndex, pageCount);           
                sb.AppendFormat("</div>");            
                return sb.ToString();
            }
        }

    //页面调用分页类的分页方法:要将传如的string类型转成HtmlString类型,采用@Html.Raw(string str)函数

    @{
    string href = "/UserInfo/Index/";
    @Html.Raw(PageBarHelper.GetPageBar(href, (int)ViewData["recordcount"], (int)ViewData["pageIndex"], (int)ViewData["pageSize"]));
    }

  • 相关阅读:
    软工小白菜的团队介绍和采访
    团队作业第二次——团队Github实战训练
    团队作业第一次—团队展示和项目展示
    week5:Technology: Internets and Packets
    week3:History: The Web Makes it Easy to Use
    week2:History: The First Internet
    week4:History: Commercialization and Growth
    week1:History: Dawn of Electronic Computing
    第二日会议博客
    第一日会议博客
  • 原文地址:https://www.cnblogs.com/CelonY/p/10652060.html
Copyright © 2011-2022 走看看