我在标准 C# ASP.NET MVC 控制器中有以下代码。
public JsonResult ReadTeachers()
{
return Json(ReadTeacherData(), JsonRequestBehavior.AllowGet);
}
public void UpdateTeachers(IEnumerable<Teacher> updatedTeachers)
{
// this is never called
}
我试图用 KendoGrid 调用这个控制器。这是我的网格的代码。
$("#teachers").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: '@Url.Action("ReadTeachers", "EducationPortal")',
dataType: "json"
},
update: {
url: '@Url.Action("UpdateTeachers", "EducationPortal")',
dataType: "json"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
schema: {
model: {
id: "TeacherId",
fields: {
TeacherId: { type: "number" },
FullName: { type: "string" },
IsHeadmaster: { type: "boolean" }
}
}
}
},
toolbar: ["create", "save"],
columns: [
{ field: "FullName", title: "Teacher" },
{ field: "IsHeadmaster", title: "Is a Headmaster?", width: "120px" },
{ command: ["destroy"], title: " ", width: "85px" }],
editable: true
});
我从 Kendo 改编了这段代码examples http://demos.telerik.com/kendo-ui/web/grid/editing.html。问题是,UpdateTeachers 方法永远不会被调用。我怀疑问题出在parameterMap函数上,因为这是我理解最少的代码部分。