my ajax code
function gonder() {
var params = {
DonationInfo: {
name: $('#name').val(),
lastname: $('#lastname').val(),
phone: $('#phone').val(),
type: $('#type').val(),
amounth: $('#amounth').val(),
quentity: $('#quentity').val()
}
};
$.ajax({
url: '@Url.Action("Index", "Benafactor")',
type: 'POST',
async: true,
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert(data.success);
$('#target').html(data);
},
error: function () {
alert("error");
}
});
}
MY Controller
[System.Web.Http.HttpPost]
public ActionResult Index([FromBody] Mymodel data)
{
return Json(new { success = true });
}
also i tried with string
and here is Mymodel
public class Mymodel
{
public string name { get; set; }
public string lastname { get; set; }
public string phone { get; set; }
public string type { get; set; }
public string amounth { get; set; }
public string quentity { get; set; }
}
i tried hard , looked for the all same question but nothing work for me please help i can see the data in request payload but can't get the parameters into controller
contentTypeoption and usedata: $('form').serialize(),(.serialize()` correctly serializes your form controls to json)