I’m using a FormCollection to get client input on an ASP.Net MVC view. I was using a checkbox, and I would just check to see if the FormCollection’s AllKeys list contained the name of the checkbox I was checking. I now need to switch to a radio button, but since the inputs need to have the same name (which seems a bit silly to me), I can’t determine which radio button was selected.
Or can I?
Well if you have three radio buttons all with the same name, then when you get the values back in the form collection, the value of that key will be the value of the selected radio button. That is how they work. They use the same name as a logical grouping so selecting one, deselects the previous. So you can assume that the value is the value of the selected radio button if you identify the group by name!
Andrew