private static string CreatePageBtns(int cur, int total, MotyPagerOption option) { StringBuilder sb = new StringBuilder(); sb.Append("<div class='motypc_horizontal_pager_btn'>"); foreach (var page in GetPagesToShow(cur, total, option.PageBtnCount)) { if (page == cur) { sb.AppendFormat("<a href='javascript:void(0)' style='color:{0}; background-color:{1};border-color:transparent'>{2}</a>", ColorTranslator.ToHtml(option.CurrentForeColor), ColorTranslator.ToHtml(option.CurrentBackColor), page); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(page), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", page); } } sb.Append("</div>"); return(sb.ToString()); }
//生成 private static string CreateHtml(int cur, int total, MotyPagerOption option) { StringBuilder sb = new StringBuilder(string.Empty); sb.Append("<div class='motypc_1604261319'>"); #region 首页 if (option.ShowFirst) { if (cur == 1) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.FirstText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.FirstText); } } #endregion #region 一页 if (option.ShowPrev) { if (cur == 1) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.PrevText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(cur - 1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.PrevText); } } #endregion #region 中间页面按钮 if (option.Responsive) { sb.Append(CreatePageBtns(cur, total, option)); sb.Append(CreateSelect(cur, total, option)); } else { if (option.IsPcStyle) { sb.Append(CreatePageBtns(cur, total, option)); } else { sb.Append(CreateSelect(cur, total, option)); } } #endregion #region 一页 if (option.ShowNext) { if (cur == total) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.NextText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(cur + 1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.NextText); } } #endregion #region 尾页 if (option.ShowLast) { if (cur == total) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.LastText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(total), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.LastText); } } #endregion sb.Append("</div>"); return(sb.ToString()); }
/// <summary> /// 生成分页HTML文本。 /// </summary> /// <param name="helper"></param> /// <param name="cur">当前页。</param> /// <param name="total">总页数。</param> /// <param name="option">分页选项。</param> /// <returns></returns> public static MvcHtmlString MotyPager(this HtmlHelper helper, int cur, int total, MotyPagerOption option) { return(MvcHtmlString.Create(Create(cur, total, option))); }