7.5.1.2 Adding the HTML Helper Method; Listing 7-18. The Contents of the PagingHelpers.cs Class File
parent
d7dcb89a64
commit
7539975905
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using SportsStore.WebUI.Models;
|
||||||
|
|
||||||
|
namespace SportsStore.WebUI.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");
|
||||||
|
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");
|
||||||
|
result.Append(tag.ToString());
|
||||||
|
}
|
||||||
|
return MvcHtmlString.Create(result.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ using System.Web;
|
||||||
|
|
||||||
namespace SportsStore.WebUI.Models
|
namespace SportsStore.WebUI.Models
|
||||||
{
|
{
|
||||||
public class PaingInfo
|
public class PagingInfo
|
||||||
{
|
{
|
||||||
public int TotalItems { get; set; }
|
public int TotalItems { get; set; }
|
||||||
public int ItemsPerPage { get; set; }
|
public int ItemsPerPage { get; set; }
|
|
@ -121,8 +121,9 @@
|
||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="HtmlHelpers\PagingHelpers.cs" />
|
||||||
<Compile Include="Infrastructure\NinjectDependencyResolver.cs" />
|
<Compile Include="Infrastructure\NinjectDependencyResolver.cs" />
|
||||||
<Compile Include="Models\PaingInfo.cs" />
|
<Compile Include="Models\PagingInfo.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue