How to pass Multiple Parameters from ajax call to MVC Controller
You're making an HTTP POST, but trying to pass parameters with the GET query string syntax. In a POST, the data are passed as named parameters and do not use the param=value&foo=bar
syntax. Using jQuery's ajax method lets you create a javascript object with the named parameters, like so:
$.ajax({
url: '/Home/SaveChart',
type: 'POST',
async: false,
dataType: 'text',
processData: false,
data: {
input: JSON.stringify(IVRInstant.data),
name: $("#wrkname").val()
},
success: function (data) { }
});
In addition to posts by @xdumain, I prefer creating data object before ajax call so you can debug it.
var dataObject = JSON.stringify({
'input': $('#myInput').val(),
'name': $('#myName').val(),
});
Now use it in ajax call
$.ajax({
url: "/Home/SaveChart",
type: 'POST',
async: false,
dataType: 'json',
contentType: 'application/json',
data: dataObject,
success: function (data) { },
error: function (xhr) { } )};