title: Boolean value of True for required attribute on MVC .net property
body: <p>How do I require a value of <code>True</code> for a <code>boolean</code> property in MVC 3 with .NET?
  This is where I am, I need the value to be <code>True</code> othewise it's not valid</p>
  
  <pre><code>&lt;Required()&gt; _
  &lt;DisplayName("Agreement Accepted")&gt; _
  Public Property AcceptAgreement As Boolean
  </code></pre>
  
  <p>Here is the fix in case the link dies someday</p>
  
  <p>Add this class</p>
  
  <pre><code>Public Class BooleanMustBeTrueAttribute Inherits ValidationAttribute
  
      Public Overrides Function IsValid(ByVal propertyValue As Object) As Boolean
          Return propertyValue IsNot Nothing AndAlso TypeOf propertyValue Is Boolean AndAlso CBool(propertyValue)
      End Function
  
  End Class
  </code></pre>
  
  <p>Add attribute</p>
  
  <pre><code>&lt;Required()&gt; _
  &lt;DisplayName("Agreement Accepted")&gt; _
  &lt;BooleanMustBeTrue(ErrorMessage:="You must agree to the terms and conditions")&gt; _
  Public Property AcceptAgreement As Boolean
  </code></pre>