c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

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

| | CSharp , Linq , MVC

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

I got this above error while running the asp.net mvc application.I want to generate paging control for grid. So I had installed pagedList Library in the application. I used the following function,

      public ActionResult Index(int? page)
        {
            int maxRows = 5;
            int pageNumber = (page ?? 1);
            return View(db.Staffs.ToPagedList(pageNumber, maxRows));
        } 

Solution:

You should convert IList or IEnumerable into IQueryable in asp.net MVC Application like below. 

  public ActionResult Index(int? page)
        {
            int maxRows = 5;
            IQueryable<Staff> staffs = (from staff in db.Staffs
                                        select staff)
                        .OrderBy(student =>student.StaffId);
            int pageNumber = (page ?? 1);
            return View(staffs.ToPagedList(pageNumber, maxRows));
       }