我正在使用 ASP.NET
我想从 JS 将一些数据发送到我的控制器(在 DataBase 中设置这个日期)。我试过使用“fetch”,但对象为空。
MyController 名称:HomeController,
我的操作:ResultPage,
我要发送的数据:testResult
PS 我使用 System.Web.Http 中的 [FromBody];
console.log(testResult); // have some data
fetch('/Home/ResultPage',
{
method: 'post',
body: JSON.stringify(testResult)
})
[System.Web.Mvc.HttpPost]
public void ResultPage([FromBody] TestResult testResult)
{
// testResult is null
//some code here
}
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; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句