我在我的应用程序中使用带有 WEB API 的 MVC。我正在使用带有弹出编辑功能的 Kendo Grid。我能够获取数据并绑定网格。但是当我尝试编辑或删除一行时,问题就出现了。parameterMap 的操作参数:function(options, operation)一直显示为create并且在更新和销毁的情况下会命中相同的创建传输 url。
我在这段代码中做错了什么:
dataSource = new kendo.data.DataSource({
type: "json",
transport: {
read: {
cache: false,
url: GETUSER_API_URL,
contentType: "application/json; charset=utf-8",
datatype: "json"
},
create: {
cache: false,
url: UPDATEUSER_API_URL,
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
update: {
cache: false,
url: UPDATEUSER_API_URL,
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
destroy: {
url: DELETEUSER_API_URL,
contentType: "application/json; charset=utf-8",
type: "POST",
datatype: "json"
},
parameterMap: function (options, operation) {
debugger;
if (operation == "update" || operation == "create") {
if (options.models[0].UserProfileId == null && operation != "destroy") {
operation = "create";
}
else {
operation = "update";
}
return kendo.stringify({ models: options.models[0] });
}
else if (operation == "destroy") {
return kendo.stringify({ models: options.models[0] });
}
}
},
batch: true,
pageSize: 10,
schema: {
model: {
id: "UserProfileID",
fields: {
FirstName: { validation: { required: true } },
LastName: { validation: { required: true } },
EmailId: { nullable: false, validation: { required: true } }
}
}
}
});
此外,我如何将行数据发送回 API?