2014-12-27 122 views
0

我有這個KendoUI網格,它調用一個控制器方法來顯示一些數據。這個調用是成功的,通過查看Fiddler,我可以發現數據實際上被返回。但它並沒有顯示在所有列中。KendoUI網格問題

這裏是我的網格:

$("#someGrid").kendoGrid({ 
    height: 400, 
    columns: [ 
     { field: "ProductID", width: "60px", title: "ID" }, 
     { field: "ProductName", width: "150px", title: "Name" }, 
     { field: "Price", width: "300px", title: "Price" }, 
     { field: "VAT", width: "100px", title: "VAT" }, 
     { field: "Discount", width: "100px", title: "Discount" } 
    ], 
    editable: false, // enable editing 
    //editable: "inline", 
    //pageable: false, 
    //sortable: false, 
    //filterable: false, 
    dataSource: { 
    // serverPaging: true, 
    // serverFiltering: true, 
    // serverSorting: true, 
     pageSize: 10, 
     schema: { 

      model: { // define the model of the data source. Required for validation and property types. 
       id: "ProductID", 
       fields: { 
        ProductID: { editable: false, nullable: true}, 
        ProductName: { type: "string", editable: false }, 
        Price: { type: "number", validation: { required: true, min: 1 } }, 
        VAT: { type: "number", validation: { required: true, min: 1 } }, 
        Discount: { type: "number", editable: true, validation: {required: false} } 
       } 
      } 
     }, 
     //requestEnd: onRequestEnd, 
     //batch: true, // enable batch editing - changes will be saved when the user clicks the "Save changes" button 
     transport: { 
      read: { 
       url: "Product/GetPrices?productIDs="+productIDs, //specify the URL which should return the records. This is the Read method of the HomeController. 
       contentType: "application/json", 
       type: "POST" //use HTTP POST request as by default GET is not allowed by ASP.NET MVC 
      }, 
      parameterMap: (ProductsPriceList)=> JSON.stringify(ProductsPriceList) 
      } 
     } 
    }); 

這裏是我的控制器方法:

public ActionResult GetPrices(List<string> productIDs) 
{ 
    var prodIDs = ParseHelper.ParseDelimitedString(productIDs, ','); 

    var productsPriceList = new List<ProductPriceVM>(); 

    var productSelectorVM = new ProductSelectorVM(); 

    foreach (var prodID in prodIDs) 
    { 
     if (!string.IsNullOrEmpty(prodID)) 
     { 
      var productPriceVM = new ProductPriceVM(); 
      int intProdID; 
      var result = int.TryParse(prodID, out intProdID); 
      var product = _productRepository.GetAllProducts().SingleOrDefault(p => p.ProductID == intProdID); 
      if (product != null) 
      { 
       productPriceVM.ProductName = product.ProductName; 
       productPriceVM.ProductID = product.ProductID; 

       productPriceVM.Price = product.UnitPrice; 

       productPriceVM.VAT = product.VAT; 
      } 
      productsPriceList.Add(productPriceVM); 
      productSelectorVM.ProductPriceList = productsPriceList; 
     } 
    } 
    return Json(new { ProductsPriceList = productsPriceList.ToList(), ok = true }, JsonRequestBehavior.AllowGet); 
} 
+0

您是否檢查瀏覽器接收到的來自控制器的響應?你能把它包含在你的原始問題中嗎? – OnaBai

回答

0

嘗試改變transport->讀 - >數據類型爲JSON。因爲kendo ui datasource默認讀取的是dataType jsonp。

transport: { 
     read: { 
      url: "Product/GetPrices?productIDs="+productIDs, 
      contentType: "application/json", 
      type: "POST", 
      dataType: "json" 
     }, 
     parameterMap: (ProductsPriceList)=> JSON.stringify(ProductsPriceList) 
     } 
    } 
0

試試這個,在parameterMap,不要串聯結果。您已經返回JSON,因此不需要對已經是JSON字符串的結果進行字符串化。

僅供參考,HTML5的劍道演示包括此:

if (operation !== "read" && options.models) { 
    return {models: kendo.stringify(options.models)}; 
} 

...換句話說,他們不字符串化的讀取結果。