问题
I am trying to send array object to mvc controller from kendo datasource read methods and unable to bind parameter studentId
in GetAllStudentDetails
Methods.
var studentId=[1,2,3]
var preSelectStudentDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/Manage/Students/GetAllStudentDetails',
dataType: "json",
contentType: "application/json;charset=utf-8",
data: { studentId: studentId}
}
},
schema: {
success: "success",
message: "message",
data: "data",
model: {
id: "StudentId"
}
},
autoBind: true
})
In Controller Side
public JsonResult GetAllStudentDetails(int[] studentId)
{
JsonResult result = null;
// Code
return result;
}
回答1:
Making traditional=true it work for me
var studentId=[1,2,3]
var preSelectSegmentDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/Manage/Students/GetAllStudentDetails',
dataType: "json",
traditional: true,
contentType: "application/json;charset=utf-8",
data: { studentId: studentId}
}
},
schema: {
success: "success",
message: "message",
data: "data",
model: {
id: "StudentId"
}
},
autoBind: true
})
Or with JSON.stringify()
var preSelectedSegmentDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/Manage/Students/GetAllStudentDetails',
dataType: "json",
type: "POST",
contentType: "application/json;charset=utf-8",
},
parameterMap: function (options, operation) {
var studentId=[1,2,3]
if (operation == "read") {
return JSON.stringify({ studentId: studentId});
}
}
},
schema: {
success: "success",
message: "message",
data: "data",
model: {
id: "StudentId"
}
},
autoBind: true
})
来源:https://stackoverflow.com/questions/56382671/how-to-pass-array-object-as-a-parameter-in-kendo-datasource-read-methods