Why is a Boolean value in MVC required

I had a Boolean value in my model that worked fine when it was set to true, but when set to false, the ModelState was reporting an error for that value, saying it was required. This isn’t what I wanted. So I found a Stack Overflow question about the exact same thing.

To get around this issue, I had to change my property definition my Boolean became a nullable Boolean:

public bool? IsNewUser { get; set; }
  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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: