I am facing an issue with sending a complex JavaScript array to my asp.net mvc6 controller method. I have tried two different methods to pass the data, but neither seem to be working for me.
public IActionResult TakeComplexArray(IList<ComplexArrayInfoModel> data)
{
return PartialView(data);
}
The second method that I tried is:
public IActionResult TakeComplexArray(ComplexArrayInfoModel[] data)
{
return PartialView(data);
}
The complex JavaScript array that I am trying to send looks like this:
[Object, Object, Object, Object, Object]
Each object in the array corresponds to my model class type ComplexArrayInfoModel and contains different records of this model class.
Unfortunately, I am unable to successfully send this complex JavaScript array to the controller action using the following JavaScript function:
function SendComplexData(data, row) {
return $.ajax({
url: '@Url.Action("TakeComplexArray")',
/*data.complexArray is showed above schema*/
data: JSON.stringify({ data: data.complexArray }),
type: 'POST',
dataType: 'html',
});
}
I need help figuring out how to properly send this complex array to the controller action. Additionally, without using the json.stringify method, I am unable to send the data at all.