Example #1
0
        ////
        public static MvcHtmlString ImageLinks(this HtmlHelper html, string imagePath, string altText, string Cssclass, Func <int, string> pageUrl)
        {
            var        pagingBuilder = new PagingHtmlBuilder();
            TagBuilder tag           = new TagBuilder("a");

            tag.MergeAttribute("href", pageUrl(0));
            tag.MergeAttribute("title", altText);
            tag.MergeAttribute("class", Cssclass);

            tag.InnerHtml = "<image src='" + imagePath + "' alt='" + altText + "' />";
            return(MvcHtmlString.Create(tag.ToString()));
        }
Example #2
0
        ////
        public static MvcHtmlString tagLinks(this HtmlHelper html, string childTag, string altText, string Cssclass, Func <int, string> pageUrl)
        {
            var        pagingBuilder = new PagingHtmlBuilder();
            TagBuilder tag           = new TagBuilder("a");

            tag.MergeAttribute("href", pageUrl(0));
            tag.MergeAttribute("title", altText);
            tag.MergeAttribute("class", Cssclass);

            tag.InnerHtml = childTag;
            return(MvcHtmlString.Create(tag.ToString()));
        }
Example #3
0
        ////
        public static MvcHtmlString ImageLinks(this HtmlHelper html, string imagePath, string altText, string Cssclass, Func <int, string> pageUrl, string textCenter = "")
        {
            var        pagingBuilder = new PagingHtmlBuilder();
            TagBuilder tag           = new TagBuilder("a");

            tag.MergeAttribute("href", pageUrl(0));
            tag.MergeAttribute("title", altText);
            tag.MergeAttribute("class", Cssclass);
            if (textCenter != null && textCenter.Trim().Length > 0)
            {
                tag.InnerHtml = "<image src='" + imagePath + "' alt='" + altText + "' /><span>" + textCenter + "</span>";
            }
            else
            {
                tag.InnerHtml = "<image src='" + imagePath + "' alt='" + altText + "' />";
            }
            return(MvcHtmlString.Create(tag.ToString()));
        }
Example #4
0
        public static MvcHtmlString Paging(this HtmlHelper html, PagingInfo pagingInfo, Func <int, string> pageUrl, string tag = "li")
        {
            var           pagingBuilder = new PagingHtmlBuilder();
            StringBuilder result        = new StringBuilder();

            //previous link
            string prevLink = (pagingInfo.CurrentPage == 1)
                ? pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.CurrentPage - 1), "<", tag, false, true)
                : pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.CurrentPage - 1), "<", tag);

            result.Append(prevLink);

            // only show up to 5 links to the left of the current page
            var start = (pagingInfo.CurrentPage <= 6) ? 1 : (pagingInfo.CurrentPage - 5);
            // only show up to 5 links to the right of the current page
            var end = (pagingInfo.CurrentPage > (pagingInfo.TotalPages - 5)) ? pagingInfo.TotalPages : pagingInfo.CurrentPage + 5;

            if (start > 1)
            {
                string firstLink = (pagingInfo.CurrentPage == 1)
                      ? pagingBuilder.buildHtmlItem(pageUrl(1), "1", tag, false, true)
                      : pagingBuilder.buildHtmlItem(pageUrl(1), "1", tag);
                result.Append(firstLink);

                string sunLink1 = (pagingInfo.CurrentPage == 1)
                   ? pagingBuilder.buildHtmlItem(pageUrl(start - 1), "...", tag, false, true)
                   : pagingBuilder.buildHtmlItem(pageUrl(start - 1), "...", tag);
                result.Append(sunLink1);
            }

            for (int i = start; i <= end; i++)
            {
                string pageHtml = "";
                pageHtml = (i == pagingInfo.CurrentPage)
                    ? pagingBuilder.buildHtmlItem(pageUrl(i), i.ToString(), tag, true, false)
                    : pagingBuilder.buildHtmlItem(pageUrl(i), i.ToString(), tag);

                result.Append(pageHtml);
            }

            if (end < (pagingInfo.TotalPages))
            {
                string subLink2 = (pagingInfo.CurrentPage == pagingInfo.TotalPages)
                    ? pagingBuilder.buildHtmlItem(pageUrl(end + 1), "...", tag, false, true)
                    : pagingBuilder.buildHtmlItem(pageUrl(end + 1), "...", tag);
                result.Append(subLink2);

                string endLink = (pagingInfo.CurrentPage == pagingInfo.TotalPages)
                       ? pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.TotalPages), pagingInfo.TotalPages.ToString(), tag, false, true)
                       : pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.TotalPages), pagingInfo.TotalPages.ToString(), tag);
                result.Append(endLink);
            }


            // next link
            string nextLink = (pagingInfo.CurrentPage == pagingInfo.TotalPages)
                ? pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.CurrentPage + 1), ">", tag, true, true)
                : pagingBuilder.buildHtmlItem(pageUrl(pagingInfo.CurrentPage + 1), ">", tag);

            result.Append(nextLink);


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