Tag: asp.net

Here’s a quick and dirty html helper for checkboxes in ASP.NET MVC 3. I’m sure Microsoft will eventually package one with the MVC framework just like they will a radiobuttonlist helper, but in the meantime, this one suits my purposes.

Of course, from a front-end point of view, a multi-select listbox is also an option, but checkboxes are a little more robust when it comes to user interaction. Nothing is more annoying as a user than forgetting to ctrl-click and having all your previous selections disappear.

You can probably find variations around, most that I’ve seen use a generic list of a custom class – mine uses a MultiSelectList instead, just for fun.

Small rant while I’m sorting this out – why oh why oh why doesn’t ASP.NET MVC3 ship with a RadioButtonList Html Helper? Yes I know I can roll my own, but surely, having implemented a DropDownList, they could have popped a RadioButtonList in there for us as well – maybe with an annotation on the model to say which I would prefer? There are just so many times when it just makes the data entry on the front end soooo much quicker for small lists to have radio buttons instead of a drop down.

It seems like such an obvious thing that should be in the core of the code…and I’ve spent a fair amount of time looking through the documentation, thinking I must be missing something. Grrrrr.