Skip to main content

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>

<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:

 

Update:

First, imI'm declaring a bool, then iI 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");` ` 

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, im 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");` ` 

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");` ` 
edited tags
Link
mjwills
  • 24.1k
  • 6
  • 45
  • 74
added 26 characters in body
Source Link
user2903379
  • 385
  • 3
  • 24

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, im 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");` ` 

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, im declaring a bool, then i try to set the bool to true based on the value of the radio button.

bool IsAlreadyCustomer; IsAlreadyCustomer = Convert.ToBoolean(controllerContext.HttpContext.Request.Form["RadioButton"] == "True");` ` 

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, im 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");` ` 
added 295 characters in body
Source Link
user2903379
  • 385
  • 3
  • 24
Loading
added 2 characters in body
Source Link
user2903379
  • 385
  • 3
  • 24
Loading
Source Link
user2903379
  • 385
  • 3
  • 24
Loading