7.5.1.3 Adding the View Model Data; Listing 7-21 Updating the List Method in the ProductController.cs File

chap07
Jason Zhu 2021-09-08 15:39:09 +10:00
parent 3ab9977773
commit 6164f14dfc
1 changed files with 15 additions and 4 deletions

View File

@ -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
.OrderBy(p => p.ProductID)
.Skip((page - 1) * PageSize)
.Take(PageSize));
ProductsListViewModel model = new ProductsListViewModel
{
Products = repository.Products
.OrderBy(p => p.ProductID)
.Skip((page - 1) * PageSize)
.Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = repository.Products.Count()
}
};
return View(model);
}
}
}