I am currently using an AJAX call to a Controller within an ASP.NET MVC solution. The code snippet for the AJAX call is as follows:
$.ajax({
url: "ControllerClass/ControllerMethod?date=" + date,
type: "POST",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) {
globalVariable = result; // This is for later...
DoSomething(result);
},
async: true,
processData: false
})
After performing server-side operations, the controller returns an Object with various property types (an Int, an Array of Int, and a List of Objects).
The method I use to return this data back to the JavaScript file is...
return Json(new
{
summary = objectResult
});
Now, I want to call a different Controller from the JavaScript with the information stored in my globalVariable.
var globalVariable
This variable is declared at the top of my JS file...
When trying to call the controller with that variable, here is how it looks:
$.ajax({
url: "ControllerClass/ControllerMethod?result=" + globalVariable,
type: "POST",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) {
DoSomethingNewWithThisresult(result)
},
async: true,
processData: false
})
This is the C# controller method:
public IActionResult ControllerMethod(JsonResult result)
{
DoSomethingHereWithTheResult(result);
}
However, I am facing an issue where the result variable is empty when I set a breakpoint on the last controller. Checking in Chrome shows that the variable contains the expected data. Interestingly, if I pass just one property of the object, it works fine but passing the entire object doesn't work...