I am making following AJAX call to a method in controller
var jsonParams = { name: $('#txt_name').val(), address: $('#txt_addr').val() };
var json = JSON.stringify(jsonParams);
var actionUrl = "/AddressController/SaveAddress";
alert('all ok'); //alert arrives
$.ajax({
url: actionUrl,
data: json,
dataType: "json",
type: 'POST',
async: true,
contentType: 'application/json; charset=utf-8',
success: function (response) {
// success message
}
});
And here is my controller action method
public JsonResult SaveAddress(string name, string address)
{
//code
}
Here I have put the breakpoint at SaveAddress method however when I tried to debug the code using firebug, the Ajax is called but the breakpoint does not arrive at method. Also it does nothing,.. no response, no success message, as if it is not hitting the action method at all.
What I am doing wrong here. I tried all the suggested answers posted for the similar type of questions but none of them worked.
Please help. Thanks in advance.
You can create a viewModel Like that your JsonParams Property,and getting your JSON.stringify from your controller by ViewModel.