title: How to use Data Annotations to validate a nullable int
body: <p>In an MVC 5 project, I have a model with a nullable int. For reasons that might not be productive to explain, it needs to be an nullable int and cannot be a string.</p>
  
  <pre><code>// Value can be null or an integer from 0 to 145        
  [Range(0,145)]
  public int? Criterion { get; set; }
  </code></pre>
  
  <p>The intended annotation is to provide user feedback when entering a value in a form.</p>
  
  <pre><code>Criterion: @Html.TextBoxFor(m =&gt; m.Criterion)
  &lt;span class="text-danger"&gt;@Html.ValidationMessageFor(m =&gt; m.Criterion)&lt;/span&gt;
  </code></pre>
  
  <p>While the user does get feedback when entering non-integer values, the Range attribute does not appear to work.</p>
  
  <p>In order to enforce a nullable integer range, will I need to use regular expressions, or is there a simpler way to enforce the rule?</p>