我有这个 JavaScript 片段:
$.ajax({
type: "Post",
contentType: 'application/json',
url: "../api/Pointage/GetPointages",
data: JSON.stringify({
laDate: DateConsultation,
lstcols: Collaborators,
lEquipe: equipe,
Type: 3,
}),
success: function (data) {
console.log(data);
call3(data);
}
});
服务方法的签名如下:
[HttpPost]
public List<ItemStatistiquesPointageMonth> GetPointages(Nullable<System.DateTime> laDate = null, List<Collaborateur> lstcols =null, Nullable<int> lEquipe = null, int Type = -1)
当我调用电话时,服务无法接通!!
那么这个问题的原因是什么呢?我该如何修复它?
最佳答案
创建一个模型类来反射(reflect)您在客户端中创建的对象
public class dataModel
{
public Nullable<System.DateTime> laDate { get; set; }
public List<Collaborateur> lstcols { get; set; }
public Nullable<int> lEquipe { get; set; }
public int Type { get; set; }
}
然后将其添加到带有FromBody属性的方法
[HttpPost]
public List<ItemStatistiquesPointageMonth> GetPointages([FromBody] dataModel data){}
关于javascript - http post 方法被视为 http get 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40398724/