PagedList错误:必须在方法’Skip’之前调用方法’OrderBy’

这是完整的错误消息:方法’Skip’仅支持LINQ to Entities中的排序输入。 必须在方法’Skip’之前调用’OrderBy’方法

在“PurchaseOrderController”中,我已将此代码添加到索引方法中:

// GET: PurchaseOrder public ActionResult Index(int? page) { return View(db.PurchaseOrders.ToPagedList(page ?? 1, 3)); } 

同样在“PurchaseOrders”的索引视图中,我添加了以下代码:

  @using PagedList; @using PagedList.Mvc; @model IPagedList @{ ViewBag.Title = "Index"; } 

Index

@Html.ActionLink("Create New", "Create")

您需要在表达式中添加.OrderBy()

 return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3)); 

.ToPageList()方法使用.Skip().Skip() ,因此必须首先传递有序集合。

@Html.DisplayNameFor(model => model.First().PurchaseRequest_) @Html.DisplayNameFor(model => model.First().Date) @Html.DisplayNameFor(model => model.First().Requestor) @Html.DisplayNameFor(model => model.First().Vendor) @Html.DisplayNameFor(model => model.First().DateOrdered) @Html.DisplayNameFor(model => model.First().ConfirmedWith) @Html.DisplayNameFor(model => model.First().WorkOrder_)