My code looks like the following:
@for (var i = 0; i < Model.Count; i++)
{
<h2>Question @Html.DisplayFor(x => x[i].OrderIndex) </h2>
@Html.HiddenFor(x => x[i].SurveyId)
@Html.HiddenFor(x => x[i].QuestionId)
@Html.HiddenFor(x => x[i].AnswerId)
<br />
@Html.DisplayFor(x => x[i].QuestionText)
<br />
@Html.DisplayFor(x => x[i].QuestionText)
@if (Model[i].Type == QuestionType.Single)
{
<h2>Answer</h2>
@for (var ao = 0; ao < Model[i].Answer.AnswerOptions.Count; ao++)
{
@Html.RadioButtonFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, true) @Html.Raw(" ");
@Html.LabelFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)<br />
@Model[i].Answer.AnswerOptions[ao].OptionText
}
}
}
I can get every other control type to work ok, but I'm not sure how to wire up radio buttons with my model. It's in a nested for loop.
I've also tried:
@Html.RadioButtonFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)
@Html.Raw(" ");
This should get the value, but it does not. Also, I can't get displayfor or labelfor working:
@Html.LabelFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)
<br />