我正在尝试从kendo数据源读取方法将数组对象发送到mvc控制器,并且无法绑定studentId
方法中的参数GetAllStudentDetails
。
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
})
在控制器端
public JsonResult GetAllStudentDetails(int[] studentId)
{
JsonResult result = null;
// Code
return result;
}
答案 0 :(得分:0)
保持传统= true对我有用
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
})
或使用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
})