Last post Apr 29, 2012 09:53 PM by caligali
Apr 29, 2012 12:49 AM|caligali|LINK
I have 2 radio buttons in my view:
<input type="radio" name="gender" id="female" />Female
<input type="radio" name="gender" id="male" />Male
How do I get the option the user selected in my controller? I did something like
public ActionResult GenderView(string male, string female)
but those variables were always null. How do I read the selection from the controller?
Apr 29, 2012 01:35 AM|chiragtoad|LINK
check this link this may help you out
Apr 29, 2012 01:12 PM|caligali|LINK
I dont get it. I guess I dont need it to bind, but maybe just get the selected value of the input from the controller, is that possible?
Apr 29, 2012 04:52 PM|bruce (sqlwork.com)|LINK
when a radio button is posted, like all form elements, it sends its name & value. normal html form convention is that you woudl give the radio button the same names (to make then mutually exclusive) and give then unique values, so the server can determine
which one was checked. if you folowed this convention, then in mvc for the parameter (or model property) gender, the value would be the value of the checked radio button. just add value attributes to your radio buttons.
note: in you case as you don't supply a value, there is none posted back.
Apr 29, 2012 09:53 PM|caligali|LINK
<input type="radio" name="gender" id="female" value="female" />Female
<input type="radio" name="gender" id="male" value="male"/>Male
public ActionResult GenderView(string gender)