C# ajax将int列表传递给asp net api控制器,参数为null
我想将int-id列表传递到我的控制器中,但是当数据到达控制器操作时,参数为nullC# ajax将int列表传递给asp net api控制器,参数为null,c#,asp.net-mvc,asp.net-ajax,C#,Asp.net Mvc,Asp.net Ajax,我想将int-id列表传递到我的控制器中,但是当数据到达控制器操作时,参数为null [HttpGet] public async Task<ActionResult> GetReport(int[] items) { var viewModel = await _reportLogic.GetReportByIdAsync(items); // return something; } 我做错了什么 谢谢使用POST而不是G
[HttpGet]
public async Task<ActionResult> GetReport(int[] items)
{
var viewModel = await _reportLogic.GetReportByIdAsync(items);
// return something;
}
我做错了什么
谢谢使用POST而不是GET。
在ajax中使用传统属性,设置为true
$.ajax({
url:“/home/GetReport”,
类型:“POST”,
//contentType:“应用程序/json;字符集=utf-8”,
数据:{“项目”:项目},
数据类型:“json”,
传统的:是的,
成功:功能(数据){
//做点什么
});
$(“#datos”).html(世界其他地区);
$('#authorNameTextBox').val('');
},
错误:函数(结果){
//警报(“错误”);
}
});
使用POST而不是GET。
在ajax中使用传统属性,设置为true
$.ajax({
url:“/home/GetReport”,
类型:“POST”,
//contentType:“应用程序/json;字符集=utf-8”,
数据:{“项目”:项目},
数据类型:“json”,
传统的:是的,
成功:功能(数据){
//做点什么
});
$(“#datos”).html(世界其他地区);
$('#authorNameTextBox').val('');
},
错误:函数(结果){
//警报(“错误”);
}
});
在公共异步任务GetReport([FromBody]int[]项)中使用[FromBody]在公共异步任务GetReport([FromBody]int[]项)中使用[FromBody]
$('#testPreviewList').click(function (e) {
var items = new Array();
$('.reportId').each(function () {
items.push(this.id);
});
console.log(items);
$.ajax({
url: "/home/GetReport",
type: "GET",
//contentType: "application/json; charset=utf-8",
data: { "items": items},
dataType: "json",
success: function (data) {
//do something
});
$("#datos").html(row);
$('#authorNameTextBox').val('');
},
error: function (result) {
//alert("Error");
}
});
});