Reputation: 1300
I have an array of objects that I'm passing from view to controller using ajax. Array data is:
My ActionMethod is:
public JsonResult AddQuestionsToStep(long stepId, string questionText, string questionType, string correctAnswer = "", List<QuestionOption> choices = null)
I'm receiving other variables data and count for choices array but the data in choices array is not mapped.i.e, OptionName
that has value on client side is null on server side. What i'm doing wrong?
Upvotes: 0
Views: 597
Reputation: 2691
As your choices
is a javascript array of Objects, serialize it and parse it on your backend:
choices: JSON.stringify(choices)
On your backend just parse the json:
List<QuestionOption> choices = (List<QuestionOption>) JsonConvert.DeserializeObject(choicesJson, typeof(List<QuestionOption>));
Upvotes: 1