【发布时间】:2023-03-19 12:17:01
【问题描述】:
我的 ASP.Net WebApi 应用程序中有一个奇怪的问题。我有这个客户端代码:
var arr = [];
for (var i = 0; i < checkarray.length; i++) {
if (checkarray[i] == 1) arr.push(ids[i]);
}
console.log(arr);
$.ajax({
type: "post",
async: false,
url: "/api/Demande/ReservationAgendaByDrivers",
data: arr,
success: function (data) {
// ...
}
});
在服务器端:
[HttpPost]
public IEnumerable<ReservationModel> ReservationAgendaByDrivers(int[] tab)
{
List<ReservationModel> outlst = new List<ReservationModel>();
List<ReservationModel> model = GetListReservation().ToList();
foreach (ReservationModel item in model)
{
if (!item.id_chauffeur.HasValue)
continue;
if (tab.Contains(item.id_chauffeur.Value))
outlst.Add(item);
}
return outlst.OrderByDescending(x => x.id_demande);
}
例如,作为浏览器的输出,我得到了这个数组:
[7, 5, 1]
但是服务器端的tab参数总是null!!
我需要知道:
- 出现此错误的原因是什么?
- 如何修复我的代码?
【问题讨论】:
-
async: false 不要这样做。
标签: c# jquery asp.net .net asp.net-web-api