I am trying to create a group of radio buttons on my form. I am using Razors Html.RadioButtonFor, but I am uncertain how to properly populate my Radios with the appropriate values from my model.
for (int i = 0; i < Model.Questions.Count(); i++)
{
@Html.RadioButtonFor(m => m.Questions[i].Selected, new SelectList(Model.Questions[i].Options, "Id", "Text"))
}
As you can probably notice I was trying to do the same thing you can do in a dropdownfor since they are basically the same thing.
MODELS:
public class QuestionViewModel
{
public int? Id { get; set; }
public string QuestionType { get; set; }
public string SubType { get; set; }
public string Text { get; set; }
public int SortOrder { get; set; }
public bool IsHidden { get; set; }
public int Selected { get; set; }
public List<QuestionOptionViewModel> Options { get; set; }
}
public class QuestionOptionViewModel
{
public int? Id { get; set; }
public string Text { get; set; }
public string Value { get; set; }
public bool IsChecked { get; set; }
public int Selected { get; set; }
}