-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPagingHelpers.cs
44 lines (39 loc) · 1.4 KB
/
PagingHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using MyBlog.UI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace MyBlog.UI.HtmlHelpers
{
public static class PagingHelpers
{
public static MvcHtmlString PageLinks(this HtmlHelper html,
PagingInfo pagingInfo,
Func<int, string> pageUrl)
{
StringBuilder result = new StringBuilder();
for (int i = 1; i <= pagingInfo.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
// Build I tag
var iTagBuilder = new TagBuilder("li");
tag.MergeAttribute("href", pageUrl(i));
tag.InnerHtml = i.ToString();
if (i == pagingInfo.CurrentPage)
{
tag.AddCssClass("selected");
tag.AddCssClass("btn-primary");
}
tag.AddCssClass("btn btn-default");
// Render the end tag
iTagBuilder.ToString(TagRenderMode.EndTag);
// Add the I tag to the A tag><
iTagBuilder.InnerHtml += tag.ToString();
result.Append(iTagBuilder.ToString());
}
return MvcHtmlString.Create(result.ToString());
}
}
}