1 回答

TA贡献1818条经验 获得超3个赞
如果你想用 发布数据 FormData,那么你不应该设置Content-Type为application/json.Besides,在你的操作参数上使用[FromForm]而不是[FromBody]。
1.在js代码中删除以下行
req.setRequestHeader("Content-Type", "application/json");
2.使用【FromForm】
[HttpPost]
public void Post([FromForm] Tache tache)
结果如下:
idTache:11 dateCreation:2019-10-08 dateEditorial:2019-10-22 优先级:1 已完成:在描述:测试
由于您将数据作为模型 Type 接收Tache,因此您需要传递一个名为id而不是idTache显示在日志结果中的属性。
您没有显示您的视图代码,我建议您使用name="id"该输入文本框。
在我的情况下,正确的日志结果有一个__RequestVerificationToken:,如果您使用它,它也是expeted <form id="formEdit">:
id: 11
dateCreation: 2019-10-08
dateEcheance: 2019-10-22
priorite: 1
terminee: on
description: essai
__RequestVerificationToken:xxxxxxxx
添加回答
举报