PagedList错误:之前的方法'跳过'的方法“排序依据”必须调用 [英] PagedList error: The method 'OrderBy' must be called before the method 'Skip'
本文介绍了PagedList错误:之前的方法'跳过'的方法“排序依据”必须调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是完整的错误消息:
的方法跳过仅支持在LINQ到实体排序的输入。该方法排序依据必须名为
在PurchaseOrderController我加入这个代码索引方法方法'跳过'前:
// GET:PurchaseOrder的
公众的ActionResult指数(?诠释页)
{
返回查看(db.PurchaseOrders .ToPagedList(页面?? 1,3));
}
在索引视图为个PurchaseOrders我加入这个代码,也:
@using PagedList;
@using PagedList.Mvc;
@model IPagedList< PurchaseOrders.Models.PurchaseOrder>
@ {
ViewBag.Title =指数;
}
< H2>指数< / H>
< P>
@ Html.ActionLink(新建,创建)
< / P>
<表类=表>
< TR>
<第i个
@ Html.DisplayNameFor(型号=> model.First()PurchaseRequest_。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()日期。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()请求。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()供应商。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()DateOrdered。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()ConfirmedWith。)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> model.First()WorkOrder_。)
< /第i
<第i< /第i
< / TR>
解决方案
您需要添加一个 .OrderBy()
中的表达式:
返回查看(db.PurchaseOrders.OrderBy(I = > i.SomeProperty).ToPagedList(页面?? 1,3));
的
.ToPageList()
方法使用 .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'
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>
解决方案
You need to add an .OrderBy()
in the expression:
return View(db.PurchaseOrders.OrderBy(i => i.SomeProperty).ToPagedList(page ?? 1, 3));
The .ToPageList()
method uses .Skip()
and .Take()
so it must be passed an ordered collection first.
这篇关于PagedList错误:之前的方法'跳过'的方法“排序依据”必须调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文