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

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

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

php - Cloud9 cloud IDE and CakePHP -