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
添加回答
舉報