c# - Why are my KendoGrid "update" parameters always null in the controller? -
i have following code in index.cshtml
file:
var datasource = new kendo.data.datasource({ type: "json", transport: { read: { url: '@url.action("readteachers", "educationportal")', datatype: "json" }, update: { url: '@url.action("updateteachers", "educationportal")', type: "post" }, parametermap: function (data, operation) { if (operation != "read"){ var result = {}; (var = 0; < data.models.length; i++) { var teacher = data.models[i]; (var member in teacher) { result["teacher[" + + "]." + member] = teacher[member]; } } return result; } else { return json.stringify(data); } } }, batch: true, schema: { model: { id: "teacherid", fields: { teacherid: { type: "number" }, fullname: { type: "string" }, isheadmaster: { type: "boolean" } } } } }); $("#teachers").kendogrid({ datasource: datasource, toolbar: ["create", "save"], columns: [ { field: "fullname", title: "teacher" }, { field: "isheadmaster", title: "is headmaster?", width: "120px" }, { command: ["destroy"], title: " ", width: "85px" }], editable: true });
this standard kendogrid "batch" editing. editing , grid both work fine, backend doesn't. when "update" request goes through, goes controller method:
public void updateteachers(string models) { // method have real code later console.write(models); }
when put breakpoint in here, visual studio shows models
null
. so:
why null
?
in parametermap: function ()
instead of using
return json.stringify(data);
use
return { models: kendo.stringify(data) };
here data serialize , attached name models name models used parameter name in action
Comments
Post a Comment