我正在使用 ASP.NET我想將一些數據從 JS 發送到我的控制器(在數據庫中設置此日期)。我嘗試使用“fetch”,但對象為空。MyController 名稱:HomeController、我的操作:ResultPage、我要發送的數據:testResultPS 我使用 System.Web.Http 中的 [FromBody];console.log(testResult); // have some datafetch('/Home/ResultPage', { method: 'post', body: JSON.stringify(testResult) })[System.Web.Mvc.HttpPost]public void ResultPage([FromBody] TestResult testResult){ // testResult is null //some code here}
2 回答

ITMISS
TA貢獻1871條經驗 獲得超8個贊
var data = {
name: 'John'
};
var response = fetch('Home/ResultPage', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(data)
});
[HttpPost]
public void ResultPage([FromBody]Parameter parameter)
{
//code here
}
public class Parameter
{
public string name { get; set; }
}
- 2 回答
- 0 關注
- 287 瀏覽
添加回答
舉報
0/150
提交
取消