Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to add paging to a working "Context". I have downloaded "PagedList" from NuGet.

Error Code:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.

C#
using PagedList;
using System.Data.Entity;

namespace AllIndexTables.Controllers
{
    public class HomeController : Controller
    {
        private testContext db = new testContext();
        public ActionResult Index(int? page)
        {
            int pageSize = 5;
            int pageNumber = (page ?? 1);
            return View(db.Data1.ToPagedList(pageNumber, pageSize));
        }
     }
}

Index.cshtml
HTML
@model IEnumerable<AllIndexTables.Models.Table1>
@using PagedList.Mvc;
@using PagedList;

<h2>Index</h2>

<center>
    <table>
        @foreach (var item in Model)
        {
            <tr>                {
                <td>
                    @item.Idt
                </td>
                <td>
                     @item.datetime0
                </td>
                <td>
                    @item.col1
                </td>
                <td>
                    @item.col2
                </td>
                <td>
                    @item.col3
                </td>
            </tr>
        }
    </table>
</center>
Posted

1 solution

Answered my own question:

C#
private testContext db = new testContext();
public ActionResult Index(int? page)
{
    var table1 = from s in db.Data1 select s;
    table1 = table1.OrderBy(s => s.Idt);
    int pageSize = 5;
    int pageNumber = (page ?? 1);
    return View(table1.ToPagedList(pageNumber, pageSize));
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900