First, implement IPagable in any viewmodel that you have in your project that you want to enhance with Pagination functionality.
namespace ar.com.juanpabloibanez.Samples.ViewModels
{
public class SearchProducViewModel : IPageble
{
public SearchProducViewModel()
{
PagerViewModel = new PagerViewModel();
}
public PagerViewModel PagerViewModel { get; set; }
public IEnumerable<Product> ListOfProducts { get; set; }
public bool Active { get; set; }
public string Name { get; set; }
public int Delete { get; set; }
}
}
Then use the
@Html.Pager helper method in the view and pass to it an instance of PagerViewModel class that you can obtain from your model.
@using ar.com.juanpabloibanez.MVC.PagerHelper.Helpers
@using ar.com.juanpabloibanez.Samples.ViewModels
@model SearchProducViewModel
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Active</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var product in Model.ListOfProducts)
{
<tr>
<td>@product.Name</td>
<td>@product.Price</td>
<td>@product.Active</td>
<td><button name="Delete" value="@product.Id" type="submit" class="deleteButton">Delete</button></td>
</tr>
}
</tbody>
</table>
@Html.Pager(Model.PagerViewModel)
Please check this link for more info :
PagerHelper for ASP.NET MVC3