如何在Kendo数据源读取方法中将数组对象作为参数传递? [英] How to pass array object as a parameter in kendo datasource read methods?
本文介绍了如何在Kendo数据源读取方法中将数组对象作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从kendo数据源读取方法将数组对象发送到mvc控制器,并且无法绑定GetAllStudentDetails
方法中的参数studentId
.
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
})
在控制器端
public JsonResult GetAllStudentDetails(int[] studentId)
{
JsonResult result = null;
// Code
return result;
}
推荐答案
采用传统= 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
})
这篇关于如何在Kendo数据源读取方法中将数组对象作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文