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.
caligali
Member
83 Points
268 Posts
Binding radio button selection to entity
Apr 29, 2012 04:49 AM|LINK
I have 2 radio buttons in my view:
<input type="radio" name="gender" id="female" />Female <input type="radio" name="gender" id="male" />Malepublic ActionResult GenderView(string male, string female) { }and learning..
chiragtoad
Member
212 Points
51 Posts
Re: Binding radio button selection to entity
Apr 29, 2012 05:35 AM|LINK
check this link this may help you out
http://stackoverflow.com/questions/1874845/asp-net-mvc-two-way-data-binding-of-model-to-radio-button-list-using-typed-model
caligali
Member
83 Points
268 Posts
Re: Binding radio button selection to entity
Apr 29, 2012 05:12 PM|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?
and learning..
bruce (sqlwo...
All-Star
36894 Points
5452 Posts
Re: Binding radio button selection to entity
Apr 29, 2012 08:52 PM|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.
caligali
Member
83 Points
268 Posts
Re: Binding radio button selection to entity
Apr 30, 2012 01:53 AM|LINK
worked, thanks!!
<input type="radio" name="gender" id="female" value="female" />Female
{ }and learning..