Form with list of checkboxes (best practices)
I have a view that allows the user to make a selection from an IEnumerable. The way I'm doing it now is to give each checkbox the id of the item and work with the form collection at the controller's side.开发者_JS百科
I seem to remember there to be a better way but can't remember how anymore. Are there any better practices?
I did try that myself; I would append the ID to each check item, but a friend told me to do it as:
<input type="checkbox" id="chk" checked="<%= obj.Selected %>"
value="<%= obj.Key %>" />
Then you can refer to chk in the form collection, and it would contain the array of keys for the objects selected.
精彩评论