2014-05-15 126 views
1

我使用Kendo Grid作爲我的ASP.NET MVC應用程序,它使用ajax綁定進行讀取。 它將數據綁定到第一頁,但不顯示網格的頁碼。它顯示(| < < 0>> |)。Kendo Grid not Paging data


Index.cshtml

 @(Html.Kendo().Grid<Club.Areas.Admin.Models.Users>() 
      .Name("grid")     
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .Read(read => read.Action("List1", "Home")) 
       .PageSize(5)             
      )     
      .Columns(columns => 
      { 
       columns.Bound(p => p.Id).Filterable(false).Width(100); 
       columns.Bound(p => p.NickName).Width(100); 
       columns.Bound(p => p.UserVisitLastDate).Format("{0:MM/dd/yyyy}").Width(140);      
       columns.Bound(p => p.Mobile).Width(100); 
      }) 
      .Pageable()     
      .Sortable()     
      .HtmlAttributes(new { style = "width:500px;height:430px;" })     
    ) 


的HomeController

public class HomeController : Controller 
{   
    public ActionResult Index() 
    { 
     return View(); 
    } 

    public ActionResult List1([DataSourceRequest]DataSourceRequest request) 
    { 
     List<Users> U = new List<Users>(); 
     for (int i = 0; i < 100; i++) 
     { 
      U.Add(new Users 
      { 
       NickName = "Mehdi", 
       Company = "Taral", 
       Email = "[email protected]", 
       Family = "FT", 
       HomeAddress = "Isfahan", 
       HomePhone = "03112332940", 
       IsActive = true, 
       Mobile = "09131025834", 
       Name = "Mehdi", 
       UserCreateDate = DateTime.Now, 
       UserVisitLastDate = DateTime.Now, 
       WebSite = "", 
       WorkAddress = "Mehdi", 
       PostalCode = "1234567890", 
       Id = i, 
       WorkPhone = "03117726250" 
      }); 
     } 
     DataSourceResult result = U.ToDataSourceResult(request);    
     return Json(result,JsonRequestBehavior.AllowGet);    
    } 
} 
+0

你可以發佈截圖嗎? –

回答

0

您必須將數據源的serverPaging: true,並確保從服務器的響應具有總場與項目的數量。

0

我的答案與MVC方法並不完全相關,我已將它與WebAPI控制器結合使用。數據源應該是這個樣子:

var sampleDataSource = new kendo.data.DataSource({ 
    transport: { 
     read: { 
      url: svcSampleUrl, 
      contentType: "application/json; charset=utf-8", 
      type: "POST", 
      dataType: "json" 
     }, 
     parameterMap: function (options) { 
      model.Take = options.take; 
      model.Skip = options.skip; 
      model.Sort = options.sort; 
      model.Filter = options.filter; 
      return kendo.stringify(model); 
     } 
    }, 
    schema: { 
     data: "sampleDTOList", 
     total: "totalItems", 
     model: { 
      fields: { 
       ID: { type: "number" }, 
       Label: { type: "string" }, 
       Description: { type: "string" } 
      } 
     } 
    }, 
    serverPaging: true, 
    serverFiltering: true, 
    serverSorting: true 
}); 

該模式中的總屬性是它得到的記錄總數並計算頁顯示的數量。在你的情況下,你正在接收第一頁的數據,並且網格不知道有多少數據來計算所需的總頁數。