I tried an ajax post from my view as shown below (using jQuery).
Complete Solution Here.
$(document).ready(function () {
var kk = {
Address1: "423 Judy Road",
Address2: "1001",
City: "New York",
State: "NY",
ZipCode: "10301",
Country: "USA"
};
console.log(JSON.stringify(kk));
$.ajax({
url: 'Check',
type: 'POST',
data: JSON.stringify(kk),
dataType:"json",
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data.success);
},
error: function () {
alert("error");
}
});
});
And received it in a controller (the method always invoked)
public ActionResult Check(AddressInfo addressInfo)
{
return Json(new { success = true });
}
Model here,
But when I tried to access (break point checked) the properties of the object (AddressInfo
) it always showed null
value. I tried without stringifying and stringifying. I 'm learning MVC now and a beginner. Please help