Пример #1
0
 /// <summary>
 /// 生成ajax的分页
 /// </summary>
 /// <param name="recordCount"></param>
 /// <param name="pageIndex"></param>
 /// <param name="PageSize"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static MvcHtmlString AjaxPager(int recordCount, int pageIndex, int PageSize, PagerSettings settings)
 {
     PagerBuilder pb = new PagerBuilder();
     settings.HideGoToButton = true;
     settings.HtmlRequestContext = null;
     return pb.Build(recordCount, pageIndex, PageSize, settings, (context, reques, pageindex) => "javascript:page(" + pageindex + ");");
 }
Пример #2
0
 /// <summary>
 /// 生成分页代码
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="recordCount"></param>
 /// <param name="PageSize"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, int recordCount, int PageSize, PagerSettings settings)
 {
     return Pager(helper, recordCount, -1, PageSize, settings);
 }
Пример #3
0
 /// <summary>
 /// 生成分页代码
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="recordCount">总页数</param>
 /// <param name="pageIndex">当前页</param>
 /// <param name="PageSize">页大小</param>
 /// <param name="settings">设置项</param>
 /// <returns></returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, int recordCount, int pageIndex, int PageSize, PagerSettings settings)
 {
     PagerBuilder pb = new PagerBuilder();
     settings.HtmlRequestContext = helper.ViewContext.RequestContext;
     return pb.Build(recordCount, pageIndex, PageSize, settings);
 }
Пример #4
0
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="recordCount">记录总数</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="settings">生成设置</param>
        /// <param name="urlCallback">生成设置</param>
        /// <returns></returns>
        public MvcHtmlString Build(int recordCount, int pageIndex, int pageSize, PagerSettings settings, Func<RequestContext, string, object, string> urlCallback =null )
        {
            settings.RecordCount = recordCount;
            settings.PageSize = pageSize;
            if (recordCount <= 0) return MvcHtmlString.Create("");
            int pageCount = (recordCount + pageSize - 1) / pageSize;
            if (pageCount <= 1 && !settings.ShowWherOnlyOnePages) return MvcHtmlString.Create("");
            if (pageIndex <= 0)
            {
                string pageindexStr =settings.HtmlRequestContext ==null ? "1" : settings.HtmlRequestContext.HttpContext.Request[settings.PageParameterName];
                Int32.TryParse(pageindexStr, out pageIndex);
            }
            if (pageIndex <= 0) pageIndex = 1;

            settings.CurrentPageIndex = pageIndex;
            settings.PageCount = pageCount;

            ProcPager.PagerSetting = settings;
            PagerHtmlGenerate.PagerSetting = settings;
            PagerHtmlGenerate.UrlCallback = urlCallback ?? Util.GetUrl;

            IList<PageButton> pageBtnList = new List<PageButton>();
            if (pageCount <= 1) pageBtnList = ProcPager.GetBtnLessThanOnePage();
            else if (pageIndex == 1) pageBtnList = ProcPager.GetBtnWhenFrist();
            else if (pageIndex == pageCount) pageBtnList = ProcPager.GetBtnWhenLast();
            else pageBtnList = ProcPager.GetBtnWhenDefault();

            return PagerHtmlGenerate.Generate(pageBtnList);
        }