这是我的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"
}
}
});
}
});
下拉列表已正确实施。所以有一个下拉菜单但是当我按下它时它应该发布到我的控制器方法并获取值但是我得到了这个错误:
无法阅读财产&#39;数据&#39;未定义的
这是我的行动方法:
public ActionResult GetTopItemName([DataSourceRequest] DataSourceRequest request)
{
var customer = custAdapter.GetCustomersByCustomerId(SessionStore.CustomerId);
return Json(customer, JsonRequestBehavior.AllowGet);
}
什么是数据?为什么它没有定义?
答案 0 :(得分:0)
我忘记了数据源的读取功能,所以看起来应该是这样的:
transport:{
read: {
url: '/Discount/GetTopItemName',
dataType: "json",
type: "POST",
contentType: "application/json"
},
}
答案 1 :(得分:0)
我今天遇到了同样的错误,我认为你的代码中的错误就在这行:
Id: { type: "number" }, //THIS IS WRONG!!!
......应该是:
Id: { editable: false, nullable: true },