我想将字符串数组作为参数发送到服务器端。但这不管用。但我可以将字符串作为参数发送到服务器端,而不会出现任何问题。这些数据发送到mvc控制器。我使用的是jquery datatable 1.10.16。
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "test/getall",
"data": function ( d ) {
d.Ids = ["123", "333", "444"];
}
}
} );
} );发布于 2018-07-31 13:13:32
string strCommaSepList = "123,333,444";
//convert to string array
string[] strCommanSepArray = strCommaSepList.Split(",");您可以选择另一种方式将数据发送到服务器。如果您通过逗号空字符串发送数据,如"123,333,444“,那么在服务器端,您可以通过内置的explode函数将其转换为数组
发布于 2018-07-31 13:22:35
正如@TetsuyaYamamoto建议的那样,可以通过将应用程序“contentType”:“/ json”添加到请求并使用return JSON.stringify(d)将数据作为json返回来实现。
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "test/getall",
"contentType": "application/json",
"data": function ( d ) {
d.Ids = ["123", "333", "444"];
return JSON.stringify(d);
}
}
} );
} );发布于 2020-04-22 03:42:47
你可以使用整数数组,也许这段代码会对你有所帮助。
"ajax": {
"url": "testUrl",
"data": function(d) {
d.ids=integerArray.join(',');
},
}https://stackoverflow.com/questions/51605681
复制相似问题