I installed the PagedList.MVC Nugget package and I'm trying to make a PagedList from a list, List<MyProject.ViewModel.AddProducts>ProductsList
In my View:
@model PagedList.IPagedList<MyProject.ViewModel.AddProductsViewModel>
@using PagedList.Mvc;
stuff here
<table class="table" align="left" style="padding-left:15px">
<tr>
<th>
Product
</th>
</tr>
@foreach (var item in Model.ProductsList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Descripcion)
</td>
</tr>
}
</table>
Página: @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) de: @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new
{
page,
sortOrder =
ViewBag.CurrentSort,
currentFilter = ViewBag.CurrentFilter
}))
My controller:
public ActionResult NewSale(int? page=null)
{
page = (page ?? 1);
var productspl = db.Products
.Include(p => p.Category)
.Include(p => p.Color).OrderBy(p => p.Description).ToPagedList((int)page, 8);
var saleViewModel = new AddProductsViewModel
{
ProductsList = productospl,
};
return View(saleViewModel);
}
My ViewModel:
namespace MyProject.ViewModel
{
public class AddProductsViewModel
{
stuff
public List<Productos> ListaProductos { get; set; }
}
}
The problem is that I can't access the ProductsList without changing this
@model PagedList.IPagedList<MyProject.ViewModel.AddProductsViewModel>
Is there a way?