7.5 Adding Pagination; Listing 7-16 Adding Pagination Support to the List Action Method in the ProductController.cs File
parent
72064ff65c
commit
a0d696df62
|
@ -10,15 +10,19 @@ namespace SportsStore.WebUI.Controllers
|
||||||
public class ProductController : Controller
|
public class ProductController : Controller
|
||||||
{
|
{
|
||||||
private IProductRepository repository;
|
private IProductRepository repository;
|
||||||
|
public int PageSize = 4;
|
||||||
|
|
||||||
public ProductController(IProductRepository productRepository)
|
public ProductController(IProductRepository productRepository)
|
||||||
{
|
{
|
||||||
this.repository = productRepository;
|
this.repository = productRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewResult List()
|
public ViewResult List(int page = 1)
|
||||||
{
|
{
|
||||||
return View(repository.Products);
|
return View(repository.Products
|
||||||
|
.OrderBy(p => p.ProductID)
|
||||||
|
.Skip((page - 1) * PageSize)
|
||||||
|
.Take(PageSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue