Пример #1
0
 public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl)
 {
     var result = new StringBuilder();
     for (var i = 1; i <= pagingInfo.TotalPages; i++)
     {
         var tag = new TagBuilder("a");
         tag.MergeAttribute("href", pageUrl(i));
         tag.InnerHtml = i.ToString();
         if (i == pagingInfo.CurrentPage)
         {
             tag.AddCssClass("selected");
             tag.AddCssClass("btn-primary");
         }
         tag.AddCssClass("btn");
         result.Append(tag);
     }
     return MvcHtmlString.Create(result.ToString());
 }
Пример #2
0
        public void Can_Generate_PAge_Links()
        {
            HtmlHelper myHelper = null;

            var pagingInfo = new PagingInfo
            {
                CurrentPage = 2,
                TotalItems = 28,
                ItemsPerPage = 10
            };

            Func<int, string> pageUrlDelegate = i => "Page" + i;

            var result = myHelper.PageLinks(pagingInfo, pageUrlDelegate);

            Assert.AreEqual(@"<a class=""btn btn-default"" href=""Page1"">1</a>"
                            + @"<a class=""btn btn-default btn-primary selected"" href=""Page2"">2</a>"
                            + @"<a class=""btn btn-default"" href=""Page3"">3</a>",
                result.ToString());
        }