0

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("&nbsp;");
            @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("&nbsp;");

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 />
Dylan
  • 37
  • 2
  • 7
  • Please note that the model-view-controller tag is for questions about the pattern. There is a specific tag for the ASP.NET-MVC implementation. –  Jul 19 '16 at 22:53
  • Your code suggests your model are not correct - you need a property to bind the selected answer to (currently each radio button is binding to a different property and they are not even grouped). Refer [this answer](http://stackoverflow.com/questions/28055287/asp-net-mvc-5-group-of-radio-buttons/28057533#28057533) for a starting point. –  Jul 19 '16 at 22:58

0 Answers0