I have an MVC project that has a radio button. Im using a custom input so it looks a bit like this.
<input class="cb_yes" data-val="true" data-val-required="You must select" id="radio_Yes" name="RadioButton" type="radio" value="True">
<span id="radio-yes"></span>Yes</label>
<input class="cb_no" data-val="true" data-val-required="You must select" id="radio_No" name="RadioButton" type="radio" value="False">
<span id="radio-no"></span>No</label>
Notice that the name
is the same.
When Yes is clicked, in the browser console I can do
$("input[name='RadioButton']").val()
and it came back as True
. So far so good.
I'm then doing some C# to convert this value to a c# bool.
I'm doing
IsAlreadyCustomer = Convert.ToBoolean(controllerContext.HttpContext.Request.Form["RadioButton"] == "True");
but it's coming back as false
. I'm looking in the "QuickWatch" to test and doing
controllerContext.HttpContext.Request.Form["RadioButton"] == "True"
but thats, no suprise, false.
I cant seem to see why it's coming back as false. I dont get why my browser says True but QuickWatch is saying false
Have I wrote it correctly? What am I doing wrong?
Update:
First, I'm declaring a bool, then I try to set the bool to true based on the value of the radio button.
bool IsAlreadyCustomer;
//if null then false, else
IsAlreadyCustomer = Convert.ToBoolean(controllerContext.HttpContext.Request.Form["RadioButton"] == "True");`
`