簡體   English   中英

ASP數據模型中的ASP.net MVC4網格

[英]ASP.net MVC4 Grid in EF data Model

我正在嘗試在我的項目中使用GRID.MVC ,但是我得到了這個錯誤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. 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. _grid.cshtml文件的第27行:

 Ligne 25 : @helper RenderGridBody()
Ligne 26 : {
Ligne 27 :     if (!Model.ItemsToDisplay.Any())
Ligne 28 :     {
Ligne 29 :     <tr class="grid-empty-text">

這是我的看法:

@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)

請問如何解決?

只是你知道, .WithPaging會導致這種情況。 它使GridView只接受排序列表。 這意味着傳遞未排序的列表將引發異常。

// Passing this to the gridview will throw an exception because it is not sorted.
var offre = db.OFFRE.Include(o => o.REGION); 

解決方案是在將列表傳遞到網格視圖之前“排序”列表。

var offre = db.OFFRE
    .Include(o => o.REGION)
    .OrderBy(c => c.OFFRE_ID); // This converts the list into a sorted list.

return View(offre);

要解決此問題,我必須在Controler結果中添加OrderBy,如下所示:

public ActionResult Index()
        {
            var offre = db.OFFRE.Include(o => o.REGION);
            return View(offre.OrderBy(c => c.OFFRE_ID));
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM