7.5.1.3 Adding the View Model Data; Listing 7-21 Updating the List Method in the ProductController.cs File
parent
3ab9977773
commit
6164f14dfc
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using SportsStore.Domain.Abstract;
|
||||
using SportsStore.WebUI.Models;
|
||||
|
||||
namespace SportsStore.WebUI.Controllers
|
||||
{
|
||||
|
@ -19,10 +20,20 @@ namespace SportsStore.WebUI.Controllers
|
|||
|
||||
public ViewResult List(int page = 1)
|
||||
{
|
||||
return View(repository.Products
|
||||
ProductsListViewModel model = new ProductsListViewModel
|
||||
{
|
||||
Products = repository.Products
|
||||
.OrderBy(p => p.ProductID)
|
||||
.Skip((page - 1) * PageSize)
|
||||
.Take(PageSize));
|
||||
.Take(PageSize),
|
||||
PagingInfo = new PagingInfo
|
||||
{
|
||||
CurrentPage = page,
|
||||
ItemsPerPage = PageSize,
|
||||
TotalItems = repository.Products.Count()
|
||||
}
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue