MVC CheckBox returning “true,false”

Have you noticed that if you create a CheckBox in an MVC view like so:

@Html.CheckBox("SendPassword")

And then check the value of this control in the controller after you have checked it:

Request["SendPassword"]

You see this instead of “true”:

true,false

You can handle this a couple of ways, but I chose to roll with the punches. I receive the value as a string and if the value is “true,false”, then that means true:

string result = Request["SendPassword"].ToString();
bool isChecked = result.Contains("true,false");
if (isChecked) {
 // Stuff
}
Advertisements

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: