When I retrieve an array in a loop and pass it through an ajax call to my C# method, I'm encountering a problem where only null values are being received in my parameter. The count of the array is coming through, but the actual data seems to be lost. Before passing it through the ajax call, the array has a count of 3 with all the necessary information populated. However, when debugging in Visual Studio, the parameter for the list ends up being null while still maintaining a count of 3?
let test = $('.divtest').map(function (index, element) {
return {
key1: $(element).closest('.testdiv')[0].id,
key2: $(element).attr('id'),
key3: $(element).attr('style')
}
}).get();
Ajax Call
$.ajax({
cache: false,
type: "POST",
data: { test: test},
dataType: "json",
url: "/controller/testhere",
success: function (result) {
alert('done');
}
});
C# Method
public JsonResult testhere(List<string> test)
{
//stuff
return null;
}