You need to define a model to get the data from the request body. The [FromBody] attribute can only be used once in an action.
Model:
public class ViewModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
}
View:
fetch('/Home/Kaydet', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ "Id": 1, "FirstName": 'a', "LastName": 'b', "Address": 'c' })
})
Controller:
[HttpPost]
public JsonResult Kaydet([FromBody]ViewModel viewModel)
{
return Json(new { status = 0 });
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…