asp.net - How to get value of a Radiobuttonfor(created using loop) -


view

the increment not work

int = 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 debug can't value of radiobutton 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 value on post:( appreicated :))))

don't use foreach brokes model binding stephen muekle said.

you should either define editortemplate each model. or use for loop:

for (int = 0; < model.count(); i++) { <div>        @if(model[i].mcchoices.any())       {           (int j = 0; j < model[i].mcchoices.count(); j++)           {             @model[i].mcchoices[j].question_desc             (int t = 0; t < model[i].mcchoices[j].count(); t++)             {                    @html.radiobuttonfor(model => model[i].mcchoices[j].mcchoices[k].qc_selectedchoice, model[i].mcchoices[j].mcchoices[k].qc_id)                    @html.displayfor(model => model[i].mcchoices[j].mcchoices[k].qc_choice)             }           }       } </div> 

i can wrong indexes couse don't understand why using 2 nested foreach mcchoices collection. hope idea.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -