Reputation: 3110
I'm trying to use GRID.MVC in my project, but i got this error System.NotSupportedException: The Skip method is only supported for sorted input in LINQ to Entities. The OrderBy method must be called before the Skip method.
at line 27 at _grid.cshtml
file :
Ligne 25 : @helper RenderGridBody()
Ligne 26 : {
Ligne 27 : if (!Model.ItemsToDisplay.Any())
Ligne 28 : {
Ligne 29 : <tr class="grid-empty-text">
and this's my view :
@Html.Grid(Model).Columns(columns =>
{
columns.Add(item => item.OFFRE_ID).Titled("Custom column title").SetWidth(110);
columns.Add(item => item.REGION.NOM).Sortable(true);
columns.Add(item => item.DESCRIPTION).Sortable(false);
columns.Add(item => item.OFFRE_DATE).Sortable(true);
}).WithPaging(20)
Please how to fix it ?
Upvotes: 0
Views: 460
Reputation: 12117
Just so you know, .WithPaging
causes this. It makes the GridView accept only sorted list. That means that passing an unsorted list will throw an exception.
// Passing this to the gridview will throw an exception because it is not sorted.
var offre = db.OFFRE.Include(o => o.REGION);
The solution is to "order" your list before passing it into the grid view.
var offre = db.OFFRE
.Include(o => o.REGION)
.OrderBy(c => c.OFFRE_ID); // This converts the list into a sorted list.
return View(offre);
Upvotes: 2
Reputation: 3110
To Slove this Problem I had to Add OrderBy in the Controler result like this :
public ActionResult Index()
{
var offre = db.OFFRE.Include(o => o.REGION);
return View(offre.OrderBy(c => c.OFFRE_ID));
}
Upvotes: 0