问题描述
这是完整的错误消息:方法跳过"仅支持 LINQ to Entities 中的排序输入.方法 'OrderBy' 必须在方法 'Skip' 之前调用
Here's the full error message: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'
在PurchaseOrderController"中,我已将此代码添加到索引方法中:
In the "PurchaseOrderController" I have added this code to the index method:
// GET: PurchaseOrder
public ActionResult Index(int? page)
{
return View(db.PurchaseOrders.ToPagedList(page ?? 1, 3));
}
也在采购订单"的索引视图中,我添加了以下代码:
Also in the Index View for "PurchaseOrders" I have added this code:
@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()
:
You need to add an .OrderBy()
in the expression:
return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3));
.ToPageList()
方法使用 .Skip()
和 .Take()
所以它必须首先传递一个有序集合.
The .ToPageList()
method uses .Skip()
and .Take()
so it must be passed an ordered collection first.
这篇关于PagedList 错误:方法 'OrderBy' 必须在方法 'Skip' 之前调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!