c# - How to display checkboxes in MVC with Razor -


i trying create view viewmodel includes many checkboxes. can list checkboxes couldnt figure out labels.

@for (int = 0; < model.colors.count; i++) {     @html.editorfor(x => x.colors[i].checked)     @html.labelfor(x => x.colors[i].color)            } 

the second line in loop displays "color" next every checkbox. proper way display value in x.color[i].color?

the first parameter of labelfor() should same used editorfor() the label associated controls (clicking on label toggles checked state of checkbox). second parameter can provided 'display text'. refer documentation

@for (int = 0; < model.colors.count; i++) {     @html.editorfor(x => x.colors[i].checked)     @html.labelfor(x => x.colors[i].checked, model.colors[i].color)      } 

Comments

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

python - argument 2 to map() must support iteration -

list - C++ | Queue: Dequeue function crashes program -