コード例 #1
0
        public static MvcHtmlString PostPagingForViewForum(this HtmlHelper helper, TopicTableViewModel model,
                                                           string actionName, string controlName, object htmlDefaultBtnAttributes)
        {
            var mainDiv       = new TagBuilder("div");
            var stringBuilder = new StringBuilder();

            if (model.PagesCount > 1 && model.PagesCount <= 5)
            {
                for (var i = 1; i <= model.PagesCount; i++)
                {
                    var a = new TagBuilder("a");
                    a.MergeAttributes(new RouteValueDictionary(htmlDefaultBtnAttributes));
                    a.Attributes.Add("href", $"/{controlName}/{actionName}?topicId={model.TopicId}&page={i}");
                    a.InnerHtml = i.ToString();

                    stringBuilder.Append(a);
                }
            }
            else if (model.PagesCount > 1)
            {
                var aFirst = new TagBuilder("a");
                aFirst.MergeAttributes(new RouteValueDictionary(htmlDefaultBtnAttributes));
                aFirst.Attributes.Add("href", $"/{controlName}/{actionName}?topicId={model.TopicId}&page={1}");
                aFirst.InnerHtml += 1.ToString();
                stringBuilder.Append(aFirst);

                var spanEllipsis = new TagBuilder("span");
                spanEllipsis.SetInnerText(" ... ");
                stringBuilder.Append(spanEllipsis);

                for (var i = model.PagesCount - 2; i <= model.PagesCount; i++)
                {
                    var a = new TagBuilder("a");
                    a.MergeAttributes(new RouteValueDictionary(htmlDefaultBtnAttributes));
                    a.Attributes.Add("href", $"/{controlName}/{actionName}?topicId={model.TopicId}&page={i}");
                    a.InnerHtml = i.ToString();

                    stringBuilder.Append(a);
                }
            }
            mainDiv.InnerHtml += stringBuilder.ToString();
            return(MvcHtmlString.Create(mainDiv.ToString()));
        }
コード例 #2
0
 public static MvcHtmlString PostPagingForViewForum(this HtmlHelper helper, TopicTableViewModel model,
                                                    string actionName, string controlName)
 {
     return(PostPagingForViewForum(helper, model, actionName, controlName, null));
 }