Esempio n. 1
0
        public static MvcHtmlString BuildPaginationWithSkippingPages(this HtmlHelper helper, PaginationModel paginationModel, Func<int, string> linkFunc)
        {
            if (paginationModel.PagesTotal <= 8)
            {
                return helper.BuildPagination(paginationModel, linkFunc);
            }

            MultiLevelHtmlTag divTag = new MultiLevelHtmlTag("div");
            divTag.AddCssClass("pagination");
            MultiLevelHtmlTag ulTag = new MultiLevelHtmlTag("ul");
            bool previusPageWasSkipped = false;
            for (int i = 1; i <= paginationModel.PagesTotal; i++)
            {
                bool skipPage = (i != 1 && Math.Abs(paginationModel.CurrentPage - i) > 2 && i != paginationModel.PagesTotal);
                if (previusPageWasSkipped && skipPage)
                {
                    continue;
                }
                previusPageWasSkipped = skipPage;
                MultiLevelHtmlTag liTag = new MultiLevelHtmlTag("li");
                if (i == paginationModel.CurrentPage)
                {
                    liTag.AddCssClass("active");
                }
                else if (skipPage)
                {
                    liTag.AddCssClass("disabled");
                }

                MultiLevelHtmlTag aTag = new MultiLevelHtmlTag("a");
                aTag.Attributes.Add("href", skipPage ? "#" : linkFunc(i));
                aTag.SetInnerText(skipPage ? "..." : i.ToString(CultureInfo.InvariantCulture));
                liTag.Add(aTag);
                ulTag.Add(liTag);
            }

            divTag.Add(ulTag);

            return MvcHtmlString.Create(divTag.ToString());
        }
Esempio n. 2
0
        public static MvcHtmlString BuildPagination(this HtmlHelper helper, PaginationModel paginationModel, Func<int, string> linkFunc)
        {
            MultiLevelHtmlTag divTag = new MultiLevelHtmlTag("div");
            divTag.AddCssClass("pagination");
            MultiLevelHtmlTag ulTag = new MultiLevelHtmlTag("ul");
            for (int i = 1; i <= paginationModel.PagesTotal; i++)
            {
                MultiLevelHtmlTag liTag = new MultiLevelHtmlTag("li");
                if (i == paginationModel.CurrentPage)
                {
                    liTag.AddCssClass("active");
                }

                MultiLevelHtmlTag aTag = new MultiLevelHtmlTag("a");
                aTag.Attributes.Add("href", linkFunc(i));
                aTag.SetInnerText(i.ToString(CultureInfo.InvariantCulture));
                liTag.Add(aTag);
                ulTag.Add(liTag);
            }

            divTag.Add(ulTag);

            return MvcHtmlString.Create(divTag.ToString());
        }