Browse all products (custom page route value key)

Product name Category
Product 21 Shoes
Product 22 Electronics
Product 23 Food
Product 24 Shoes
Product 25 Shoes
Product 26 Electronics
Product 27 Food
Product 28 Shoes
Product 29 Shoes
Product 30 Electronics

Razor code

@using MvcPaging.Demo.Models
@model IPagedList<Product>
@{
	ViewBag.Title = "Browse all products (custom page route value key)";
}
<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).Options(o => o
			.PageRouteValueKey("Search.page")
			.AlwaysAddFirstPageNumber())
</div>

Controller code

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