我有這個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);
}
您是否檢查瀏覽器接收到的來自控制器的響應?你能把它包含在你的原始問題中嗎? – OnaBai