Browse all products

Product name Category
Product 51 Food
Product 52 Shoes
Product 53 Shoes
Product 54 Electronics
Product 55 Food
Product 56 Shoes
Product 57 Shoes
Product 58 Electronics
Product 59 Food
Product 60 Shoes

Razor code

@using MvcPaging.Demo.Models
@model IPagedList<MvcPaging.Demo.Models.Product>
@{
	ViewBag.Title = "Browse all products";
}
<h2>@ViewBag.Title</h2>
<table class="grid">
	<thead>
		<tr>
			<th>Product name</th>
			<th>Category</th>
		</tr>
	</thead>
	<tbody>
		@foreach (var product in Model) { 
			<tr>
				<td>@product.Name</td>
				<td>@product.Category</td>
			</tr>
		}
	</tbody>
</table>
<div class="pager">
	@Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)
</div>

Controller code

public ActionResult Index(int? page)
{
	int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
	return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize));
}