Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  160] [ 2]  / answers: 1 / hits: 25393  / 8 Years ago, tue, january 3, 2017, 12:00:00

I have a JSON object with nested arrays which I would like to send to a controller.



This is my jQuery.ajax call:



$.ajax({
url: @Url.Action(ExportJson),
type: POST,
data: JSON.stringify(myObj),
contentType:application/json,
success: function (result) {

}
});


Controller:



public ActionResult ExportJson(string json)
{



return null;
}


Why is the json string coming back as null in the controller? Whereas console.log(JSON.stringify(myObj)) shows the correct object in browser console.


More From » jquery

 Answers
9

Change the ajax post like this;



$.ajax({
url: @Url.Action(ExportJson),
type: POST,
//************************************
data: {json : JSON.stringify(myObj)},
//************************************
contentType:application/json,
success: function (result) {

}
});

[#59473] Sunday, January 1, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antonb

Total Points: 424
Total Questions: 104
Total Answers: 101

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;