Exemplo n.º 1
0
        public void Can_Generate_Page_Links()
        {
            HtmlHelper helper = null;
            PagingInfo pagingInfo = new PagingInfo { 
                CurrentPage = 2,
                TotalItems = 28,
                ItemsPerPage = 10
            };

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

            MvcHtmlString result = helper.PageLinks(pagingInfo, pageUrlDelegate);

            Assert.AreEqual(result.ToString(), @"<li><a href=""Page1"">1</a></li>"
                + @"<li><a class=""selected"" href=""Page2"">2</a></li>"
                + @"<li><a href=""Page3"">3</a></li>");
        }
Exemplo n.º 2
0
 public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl) {
     StringBuilder builder = new StringBuilder();
     for (int i = 1; i <= pagingInfo.TotalPages; i++)
     {
         TagBuilder liTag = new TagBuilder("li");
         TagBuilder tag = new TagBuilder("a");
         tag.MergeAttribute("href", pageUrl(i));
         tag.InnerHtml = i.ToString();
         if (i == pagingInfo.CurrentPage)
         {
             tag.AddCssClass("selected");
         }
         liTag.InnerHtml = tag.ToString();
         builder.Append(liTag.ToString());
     }
     return MvcHtmlString.Create(builder.ToString());
 }