I am submitting a form to the controller, the form consists of properties which one of them is an array.
$("#parsedQuestions input").val(JSON.stringify(questionsArr));
var formData = JSON.stringify($("#trainingForm").serialize());
$.ajax({
type: "POST",
url: '@Url.Action("SaveTraining", "Training")',
data: formData,
error: function(jqXHR, textStatus, errorMessage) {
console.log(errorMessage);
},
success: function(data) {console.log(data)}
});
The questionsArr is an array, but it is being returned as a plain string like this:
"[[\"1\",\"11\",\"111\",\"1111\",\"1111\",\"11111\"],[\"1\",\"22\",\"222\",\"2222\",\"22222\",\"2222222\"]]"
My Controller
public async Task<IActionResult> SaveTraining([FromForm] KII_TrainingModel formData)
{
}
It's a 2-dimensional array supposedly.
In my model, I tried to make this property ParsedQuestions as string[][] and List.
But I only get one element, which is the formatted string array.
I have looked everywhere to find a solution but can't find one. Any answers or ideas will be appreciated.
If I don't stringify it, it looks like this:
If I do, then it returns this:
"[[\"1\",\"11\",\"111\",\"1111\",\"1111\",\"11111\"],[\"1\",\"22\",\"222\",\"2222\",\"22222\",\"2222222\"]]"
Any suggestions even as to how to convert this string to an actual array?

JSON.stringifyto convert it to JSON. Thus, you need to use a JSON module to decode it back to its component parts.