C# 页面列表错误:方法';订购人';必须在方法';跳过';
以下是完整的错误消息: 方法“Skip”仅支持LINQ to实体中的排序输入。方法“OrderBy”必须在方法“Skip”之前调用 在“PurchaseOrderController”中,我已将以下代码添加到索引方法中:C# 页面列表错误:方法';订购人';必须在方法';跳过';,c#,asp.net-mvc-5,pagedlist,C#,Asp.net Mvc 5,Pagedlist,以下是完整的错误消息: 方法“Skip”仅支持LINQ to实体中的排序输入。方法“OrderBy”必须在方法“Skip”之前调用 在“PurchaseOrderController”中,我已将以下代码添加到索引方法中: // GET: PurchaseOrder public ActionResult Index(int? page) { return View(db.PurchaseOrders.ToPagedList(page ?? 1, 3));
// 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>
@使用页面列表;
@使用PagedList.Mvc;
@IPagedList模型
@{
ViewBag.Title=“Index”;
}
指数
@ActionLink(“新建”、“创建”)
@DisplayNameFor(model=>model.First().PurchaseRequest)
@DisplayNameFor(model=>model.First().Date)
@DisplayNameFor(model=>model.First().Requestor)
@DisplayNameFor(model=>model.First().Vendor)
@DisplayNameFor(model=>model.First().DateOrdered)
@DisplayNameFor(model=>model.First().ConfirmedWith)
@DisplayNameFor(model=>model.First().WorkOrder)
您需要在表达式中添加一个.OrderBy()
:
return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3));
.ToPageList()
方法使用.Skip()
和.Take()
,因此必须首先向它传递一个有序集合。谢谢。您怎么知道我需要一个.OrderBy()?大概是因为错误消息明确告诉您了吧D我个人停止使用PagedList,只制作了我自己的viewmodel,我可以将跳过的内容传递给它,将值传递给它,并跟踪我在哪个页面上,我有多少个结果,等等。这使它更透明,我还可以将viewmodel用于其他事情。