在我的 Kendo Grid 中,我有默认的“添加新记录”按钮,并将其设置为可内联编辑。我设法将记录插入到数据库中,但是当用户对这条新记录进行更新时,它丢失了 ID。
我的代码如下所示:
var dataSource = new kendo.data.DataSource(
{
transport: {
read: {
url: '/Reports/Manage/Reports'
},
create: {
url: function (options) {
debugger;
// Ajax call to create a new record in the database
$.ajax(
{
type: 'POST',
url: '/Reports/Manage/CreateNewReport',
data: { name: options.name },
success: function (response) {
我必须在这里做点什么吗???
return;
},
error: function (repsonse) {
alert("Manage: CreateNewReport -> Ajax Error!");
}
});
return;
},
dataType: "json"
},
update: {
url: function (options) {
// Ajax call to update the Report Name in the database.
$.ajax(
{
type: 'POST',
url: '/Reports/Manage/UpdateReportName',
data: { reportId: options.reportId, name: options.name },
success: function (response) {
// do nothing
// alert("Successfully Saved Note.");
},
error: function (repsonse) {
alert("Manage: UpdateReportName -> Ajax Error!");
}
});
return;
},
dataType: "json"
}
},
pageSize: 15,
height: 500,
data: reports,
schema:
{
model:
{
id: 'reportId',
fields:
{
name: { editable: true, validation: { required: true } },
}
}
}
});
$reports.kendoGrid(
{
dataSource: dataSource,
pageable: {
refresh: true,
pageSizes: true
},
toolbar: ["create"],
columns:
[
{ field: 'name', title: 'Report', sortable: true },
{ command: ["edit", "destroy"], title: " ", width: "180px", }
],
editable: "inline",
selectable: true,
change: function (e) {
// A new report was selected.
...
}
});