开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜