7.5 Adding Pagination; e.g. 7.14 Adding Pagination Support to the Product Controller List Method
This commit is contained in:
parent
17cf2e94ba
commit
aa4002de2b
@ -9,6 +9,8 @@ namespace SportsStore.WebUI.Controllers
|
|||||||
{
|
{
|
||||||
public class ProductController : Controller
|
public class ProductController : Controller
|
||||||
{
|
{
|
||||||
|
public int PageSize = 4; // We will change this later
|
||||||
|
|
||||||
private IProductRepository repository;
|
private IProductRepository repository;
|
||||||
|
|
||||||
public ProductController(IProductRepository productRepository)
|
public ProductController(IProductRepository productRepository)
|
||||||
@ -16,9 +18,12 @@ namespace SportsStore.WebUI.Controllers
|
|||||||
repository = productRepository;
|
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…
x
Reference in New Issue
Block a user