PagedList错误:'OrderBy'必须在方法'Skip'之前调用
本文关键字:Skip 方法 调用 错误 OrderBy PagedList | 更新日期: 2023-09-27 18:17:42
完整的错误信息如下:方法'Skip'仅支持LINQ to Entities中的排序输入。方法'OrderBy'必须在方法'Skip'之前调用
在"PurchaseOrderController"中,我将以下代码添加到索引方法中:
// GET: PurchaseOrder
public ActionResult Index(int? page)
{
return View(db.PurchaseOrders.ToPagedList(page ?? 1, 3));
}
我还在索引视图中为"PurchaseOrders"添加了以下代码:
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<PurchaseOrders.Models.PurchaseOrder>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().PurchaseRequest_)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Date)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Requestor)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Vendor)
</th>
<th>
@Html.DisplayNameFor(model => model.First().DateOrdered)
</th>
<th>
@Html.DisplayNameFor(model => model.First().ConfirmedWith)
</th>
<th>
@Html.DisplayNameFor(model => model.First().WorkOrder_)
</th>
<th></th>
</tr>
您需要在表达式中添加一个.OrderBy()
:
return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3));
.ToPageList()
方法使用.Skip()
和.Take()
,因此必须首先传递一个有序集合。