views:

41

answers:

1

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.

I seem to remember there to be a better way but can't remember how anymore. Are there any better practices?

+1  A: 

Hey,

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.

Brian
Hmm, that would render my html invalid because they all have the same ID. Did you mean class="chk"?
borisCallens
He told me ID... I admit, I didn't try it, but my friend is a good architect so I trusted his judgment. Sorry for recommending something I didn't try :-)
Brian