I'm sending a value through JQuery to an MVC HttpPost action method, but instead it is getting a null value. When I send a plain string it works fine, but when I send an array it gets the null value. Here is the code.
code to send the value
function Submit() {
var QSTR = {
name: "Jhon Smith",
Address: "123 main st.",
OtherData: []
};
QSTR.OtherData.push('Value 1');
QSTR.OtherData.push('Value 2');
$.ajax({
type: 'POST',
url: '/Omni/DoRoutine',
data: JSON.stringify({ obj: 'Reynor here!' }),
// this acctually works
// and at the action method I get the object[]
// with object[0] = 'Reynor here!'
// but when I use the object I really need to send I get null
data: JSON.stringify({ obj: QSTR }), //I get null
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (msg) {
alert('ok');
},
error: function (xhr, status) {
alert(status);
}
});
}
this is the action method code:
[HttpPost]
public ActionResult DoRoutine(object[] obj)
{
return Json(null);
}
What is the solution for this and why is this happening? thanks