2016-10-23 76 views
0

我在控制器中獲取數據並將其返回json但在kendo網格中,我無法顯示該數據以及網格jost顯示錶和數據行發送。
我的控制器的代碼:在conroller中收到數據但未在kendo網格中顯示

 private IRepository<Customer> _UserDetail; 
    public UserDetailsController(IRepository<Customer> UserDetail) 
    { 
     _UserDetail = UserDetail; 
    } 

    public ActionResult Manage() 
    { 
     return View(); 
    } 

    [HttpPost] 
    public ActionResult GetUsers(DataSourceRequest userDetail) 
    { 
     var query = _UserDetail.Table.Select(x => x.Email).ToList(); 

     var gridModel = new DataSourceResult 
     { 
      Data = query, 
      Total = query.Count 
     }; 
     return Json(gridModel); 
    } 

我劍術網格視圖:

<script> 
 
       $(document).ready(function() { 
 
        $("#user-details").kendoGrid({ 
 
         dataSource: { 
 
          type: "json", 
 
          transport: { 
 
           read: { 
 
            url: "@Html.Raw(Url.Action("GetUsers", "UserDetails"))", 
 
            type: "POST", 
 
            dataType: "json", 
 

 
           }, 
 
          }, 
 
          schema: { 
 
           data: "Data", 
 
           total: "Total", 
 
           errors: "Errors", 
 
          }, 
 
          requestEnd: function(e) { 
 
           if (e.type == "update") { 
 
            this.read(); 
 
           } 
 
          }, 
 
          error: function(e) { 
 
           display_kendoui_grid_error(e); 
 
           // Cancel the changes 
 
           this.cancelChanges(); 
 
          }, 
 
          serverPaging: true, 
 
          serverFiltering: true, 
 
          serverSorting: true 
 
         }, 
 
         pageable: { 
 
          refresh: true, 
 
          numeric: false, 
 
          previousNext: false, 
 
          info:false 
 
         }, 
 
         editable: { 
 
          confirmation: true, 
 
          mode: "inline" 
 
         }, 
 
         scrollable: false, 
 
         columns: [ 
 
          { 
 
           field: "Email", 
 
           title: "User Name", 
 
           width: 200 
 
          }, 
 
          { 
 
           command: [ 
 
            { 
 
             name: "edit", 
 
             text: "@T("Admin.Common.Edit")" 
 
            }, { 
 
             name: "destroy", 
 
             text: "@T("Admin.Common.Delete")" 
 
            } 
 
           ], 
 
           width: 200 
 
          } 
 
         ] 
 
        }); 
 
       }); 
 
</script>
<div id="user-details"></div>

+0

你得到了什麼錯誤? –

+0

是的,我達到回答這個問題,但現在我收到沒有數據的空行。例如,我發送4個數據在JSON和網格顯示4個空行在網格和記錄沒有顯示。 – Mojtaba

回答

0

我的數字,其中,是我的錯。
首先我已經使用ICustomerService,實際上這種方式比IRepository好。

[HttpPost] 
    public JsonResult GetUsers([DataSourceRequest]DataSourceRequest command) 
    { 
     var details = _CustomerDetail 
      .GetAllCustomers() 
      .Where(z=>z.Email != null) 
      .Select(x => new { x.Email , x.Id }) 
      .ToList() 
      .AsQueryable(); 

     DataSourceResult result = details.ToDataSourceResult(command); 
     return Json(result, JsonRequestBehavior.AllowGet); 

    } 
相關問題