gpt4 book ai didi

c# - PagedList ViewModel 中的对象列表

转载 作者:行者123 更新时间:2023-12-04 08:56:28 26 4
gpt4 key购买 nike

我安装了 PagedList.MVC Nugget 包,我正在尝试从列表中创建一个 PagedList List ProductsList
在我看来:

@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
}))
我的 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);
}
我的 View 模型:
namespace MyProject.ViewModel
{
public class AddProductsViewModel
{
stuff


public List<Productos> ListaProductos { get; set; }
}
}
问题是我不能在不改变它的情况下访问 ProductsList
@model PagedList.IPagedList<MyProject.ViewModel.AddProductsViewModel>
有办法吗?

最佳答案

尝试这样的事情:

public class ProductsPageViewModel() 
{
public PagedList.IPagedList<MyProject.ViewModel.AddProductsViewModel> AddProductsPagedList { get; set; }
// other properties/methods for your view go here...
}
那么在你看来:
@model ProductsPageViewModel

// other HTML here....

Página: @(Model.AddProductsPagedList.PageCount < Model.AddProductsPagedList.PageNumber ? 0 : Model.AddProductsPagedList.PageNumber) de: @Model.AddProductsPagedList.PageCount
@Html.PagedListPager(Model.AddProductsPagedList, page => Url.Action("Index", new
{
page,
sortOrder =
ViewBag.CurrentSort,
currentFilter = ViewBag.CurrentFilter
}))

关于c# - PagedList ViewModel 中的对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63803036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com