【发布时间】:2016-04-20 20:16:52
【问题描述】:
我正在尝试将我的 Kendo UI 网格与嵌套模型(例如具有嵌套模型类别的产品)绑定。我已经按照文档提供了所有内容,但我无法找出我的代码有什么问题。
schema: {
data: "data",
total: "Total",
model: { // define the model of the data source. Required for validation and property types.
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1 } },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } },
CategoryName: { from: "Category.CategoryName", validate: { required: true } }
}
}
},
并在网格的列中使用此模型
columns: [
"ProductName",
{ field: "UnitPrice", format: "{0:c}", width: "150px" },
{ field: "UnitsInStock", width: "150px" },
{ field: "Discontinued", width: "100px" },
{ field: "QuantityPerUnit", width: "100px" },
{ field: "CategoryName", title: "Category", width: "100px" },
{ command: "destroy", title: "Delete", width: "110px" },
以下是我从服务器返回的模型。
var resl = productService.GetProducts(take, skip, ref Total);
var data = resl.ToList();
// Return as JSON - the Kendo Grid will use the response
return Json(new { Total = Total, data = data });
现在除了类别名称列之外,所有列都与网格成功绑定。我错过了什么或做错了什么?
更新 - 以下是我的服务器产品视图模型
public class ProductViewModel
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public string QuantityPerUnit { get; set; }
public Int32 UnitsInStock { get; set; }
public int? UnitsOnOrder { get; set; }
public int? ReorderLevel { get; set; }
public bool Discontinued { get; set; }
public int? SupplierID { get; set; }
public int? CategoryID { get; set; }
public CategoryViewModel Category { get; set; }
这就是我在客户端接收数据的方式。
【问题讨论】:
-
您能发布一个简短的数据示例吗?
-
确定我会更新我的问题
标签: javascript asp.net-mvc kendo-ui nested