这是完整的错误消息: 只有LINQ to Entities中的排序输入才支持'Skip'方法。必须在方法'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<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>
答案 0 :(得分:33)
您需要在表达式中添加.OrderBy()
:
return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3));
.ToPageList()
方法使用.Skip()
和.Take()
,因此必须首先传递有序集合。