Axios Post 问题和 .Net Core

Axios Post Issues And .Net Core

我无法使用 Axios Post 调用将数据传递到我的 asp.net 核心 2.2 web api 来完成成功的 ReactJs。只有当所有复合词(姓氏)属性都用连字符连接时,调用才会成功到达我的 API 端点,但数据无法通过。只有单字(公司)属性接收数据。我相信这是因为连字符的属性不再匹配。但是,如果属性没有连字符,我会收到 400 错误或 415 错误。当通过 Postman 发送呼叫时,所有属性都是 pascal 大小写,我完全没有任何问题。

我已经尝试了很多方法来让它在没有解决方案的情况下工作。我已将 Json 属性添加到我的 .net 对象属性中。我修改了属性也有连字符。我尝试更改我对单个单词的反应中的两个属性,并将它们与 Json 属性、e.i createdCreatedDate 进行匹配。我还在我的 post 方法中粘贴了与我的 PostMan 成功调用中使用的完全相同的 json 对象。

.net post

[HttpPost]
[Route("AddThreshold", Name = "AddThreshold")]
public ActionResult<ThresholdDTO> AddThreshold([FromBody] ThresholdDTO threshold)
{
    var thr = _thresholdService.AddThreshold(threshold);

    if (thr == null)
        return NoContent();

    return Ok(threshold);
}
  const handleAddSubmit = e => {
    e.preventDefault();

    let current_datetime = new Date();
    let formatted_date =
      current_datetime.getFullYear() +
      "-" +
      (current_datetime.getMonth() + 1) +
      "-" +
      current_datetime.getDate() +
      " " +
      current_datetime.getHours() +
      ":" +
      current_datetime.getMinutes() +
      ":" +
      current_datetime.getSeconds();

    console.log(location);

    let threshold = JSON.stringify({
      "Threshold-Id": "",
      Company: company.toString(),
      "Threshold-Type": thresholdType.toString(),
      "Threshold-Value": thresholdValue.toString(),
      "Account-Number": account.toString(),
      "Location-Number": location == "undefined" ? "" : location.toString(),
      "Expected-Amount": expectedAmount.toString(),
      "Created-Date": formatted_date.toString(),
      "Created-By": "System",
      "Updated-Date": "1900-00-00 00:00:00.000",
      "Updated-By": ""
    });

    Axios({
      method: "post",
      url: "https://localhost:44394/Threshold/AddThreshold/",
      data: threshold,
      headers: { "Content-Type": "application/json" }
    })
      .then(function(response) {
        //handle success
        console.log(threshold);
        props.handleAddClose();
      })
      .catch(function(response) {
        //handle error
        console.log(threshold);
      });
  };
AccountNumber: "87605177 (CenturyLink)"
Company: "Deere Employees Credit Union"
CreatedBy: "System"
CreatedDate: "2019-10-27 16:1:51"
ExpectedAmount: "90000"
LocationNumber: "5000"
ThresholdId: ""
ThresholdType: "Invoice Processing"
ThresholdValue: "10"
UpdatedBy: ""
UpdatedDate: "1900-00-00 00:00:00.000"

上面的对象正是 postman 成功的对象,但是我在使用 axios

时收到 400 代码

问题是我的 UpdatedDate 值没有 Json 属性可接受的格式导致整个 post 失败。