i want make table 2 columns :- first 1 contains checkboxes, second 1 contain textboxes . want bind selected checkbox textbox , value in controller in mvc.
you should store 2 collections in viewmodel. example:
public ienumerable<bool> checkboxes { get; set; } public ienumerable<string> textboxes { get; set; } public int rowscount { get; set; }
if want use mvc binding should name cells in table correctly. can create view in way:
<table> @for(int = 0; < model.rowscount; i++) { <tr> <td><input type="checkbox" id="checkboxes[" + + "]" name="checkboxes[" + + "]"/></td> <td><input type="text" id="textboxes[" + + "]" name="checkboxes[" + + "]"/></td> </tr> } </table>
mvc binding uses name property can change id if don't want have identical id , name :)
next, in controller create post method model parameter. after submit form, collections in viewmodel should binded correctly.
Comments
Post a Comment