PagedList 错误:方法 'OrderBy' 必须在方法 'Skip' 之前调用 [英] PagedList error: The method 'OrderBy' must be called before the method 'Skip'

查看:35
本文介绍了PagedList 错误:方法 'OrderBy' 必须在方法 'Skip' 之前调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是完整的错误消息:方法跳过"仅支持 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' 之前调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆