[英]Cannot read property 'data' of undefined kendo ui js grid with customdropdown
Here is my js code:这是我的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"
}
}
});
}
});
The dropdown is implemented correctly.下拉列表已正确实施。 So there is a dropdown but when i press it it's supposed to post to my controller method and get the values but i get this error:所以有一个下拉菜单,但是当我按下它时,它应该发布到我的控制器方法并获取值,但我收到此错误:
Cannot read property 'data' of undefined无法读取未定义的属性“数据”
Here is my actionmethod:这是我的操作方法:
public ActionResult GetTopItemName([DataSourceRequest] DataSourceRequest request)
{
var customer = custAdapter.GetCustomersByCustomerId(SessionStore.CustomerId);
return Json(customer, JsonRequestBehavior.AllowGet);
}
What is data?什么是数据? and why is it undefined?为什么它是未定义的?
I forgot the read function of the datasource so it should look like this:我忘记了数据源的读取功能,所以它应该是这样的:
transport:{
read: {
url: '/Discount/GetTopItemName',
dataType: "json",
type: "POST",
contentType: "application/json"
},
}
I had the same error today and I think the error in your code is in this line:我今天遇到了同样的错误,我认为您的代码中的错误在这一行:
Id: { type: "number" }, //THIS IS WRONG!!!
...should be: ...应该:
Id: { editable: false, nullable: true },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.