7.5 Adding Pagination; Listing 7-16 Adding Pagination Support to the List Action Method in the ProductController.cs File

chap07
Jason Zhu 2021-09-08 14:53:25 +10:00
parent 72064ff65c
commit a0d696df62
1 changed files with 6 additions and 2 deletions

View File

@ -10,15 +10,19 @@ namespace SportsStore.WebUI.Controllers
public class ProductController : Controller
{
private IProductRepository repository;
public int PageSize = 4;
public ProductController(IProductRepository 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));
}
}
}