这是我的js代码:
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: '/Discount/Get',
dataType: "json",
},
update: {
url: '/Discount/Update',
dataType: "json",
type: "POST"
},
destroy: {
url: '/Discount/Delete',
dataType: "json",
type: "POST"
},
create: {
url: '/Discount/Add',
dataType: "json",
type: "POST"
},
parameterMap: function (options, operation) {
if (operation == "update") {
return JSON.stringify(options);
}
if (operation == "create") {
return options;
}
if (operation == "destroy") {
return JSON.stringify(options);
}
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number" },
TopItemName: { type: "string" },
DiscountValue: { type: "number" },
}
}
}
},
toolbar: ["create", "save", "cancel"],
height: 400,
pageable: true,
columns: [
{
field: "TopItemName",
editor: topItemDropDown,
template: "#=TopItemName#"
},
{
field: "DiscountValue",
format: "{0:p0}",
editor: function (container, options) {
$("<input name='DiscountValue'>")
.appendTo(container)
.kendoNumericTextBox(
{
min: 0,
max: 1.00,
step: 0.01
});
}
}],
editable: true
});
function topItemDropDown(container, options) {
$('<input required data-text-field="TopItemName" data-value-field="TopItemName" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
transport: {
url: '/Discount/GetTopItemName',
dataType: "jsonp",
type: "POST",
contentType: "application/json"
}
}
});
}
});
下拉菜单已正确实现。所以有一个下拉菜单,但当我按下它时,它应该发布到我的控制器方法并获取值,但我收到此错误:
无法读取未定义的属性“数据”
这是我的行动方法:
public ActionResult GetTopItemName([DataSourceRequest] DataSourceRequest request)
{
var customer = custAdapter.GetCustomersByCustomerId(SessionStore.CustomerId);
return Json(customer, JsonRequestBehavior.AllowGet);
}
什么是数据?为什么它是未定义的?
我忘记了数据源的读取功能,所以它应该看起来像这样:
transport:{
read: {
url: '/Discount/GetTopItemName',
dataType: "json",
type: "POST",
contentType: "application/json"
},
}
我今天遇到了同样的错误,我认为您的代码中的错误在这一行中:
Id: { type: "number" }, //THIS IS WRONG!!!
...应该是:
Id: { editable: false, nullable: true },