VIEW
the increment does not work
int i = 0;
foreach (var x in Model)
{
<div>
@if(x.MCchoices.Any())
{
foreach (var item in x.MCchoices)
{
@item.question_desc
foreach(var choices in item.MCchoices)
{
@Html.RadioButtonFor(model => choices.qc_selectedchoice, choices.qc_id)
@Html.DisplayFor(model => choices.qc_choice)
}
}
}
@{i++;}
</div>
Whenever i debug i can't get the value of the radiobutton to my controller
MODEL
public class QuizMaker
{
public string question_desc { get; set; }
public string question_id { get; set; }
public string qc_choice { get; set; }
public string qc_id { get; set; }
public string qc_selectedchoice { get; set; }
public IEnumerable<QuizMaker> MCchoices { get; set; } }
i can't get the value on post:( help is so much appreicated :))))
Don't use foreach it brokes model binding like Stephen Muekle said.
You should either define EditorTemplate for each model. Or use
for
loop:I can be wrong with indexes couse i don't understand why you using 2 nested
foreach
forMCchoices
collection. But i hope you get the idea.