繁体   English   中英

Http post方法被视为http get方法

[英]Http post method seen as http get method

我有这个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)

当我打电话时,服务不可达!

那么这个问题的原因是什么呢? 我该如何解决?

使用参数创建模型并将其传递给post方法

[HttpPost]
public List<ItemStatistiquesPointageMonth> GetPointages([FromBody] MyModel model)

也使用dataType: "json"

创建一个模型类,以反映您在客户端中创建的对象

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){}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM