title: How to override ASP.Net MVC's default model binder so that an empty value bound to a non-nullable value type won't trigger a model validation error
body: <p>Something I've found quite frustrating in ASP.Net MVC is that the default model binder implicitly applies the <code>Required</code> annotation when binding an empty (string or null) value to a non-nullable value type instead of simply leaving the target with its default value, or at least providing an option to allow that to be the default behaviour.</p>
  
  <p>Given a scenario where it's inconvenient to change the target property type on the model to a nullable value, what's the shortest amount of code I can employ to allow the default model binder to simply skip its attempt to bind an empty value to a non-nullable value type? I'm assuming I'll need to subclass <code>DefaultModelBinder</code>, but I'm not sure what I need to override to achieve the desired behaviour.</p>
  
  <p>example:</p>
  
  <pre><code>&lt;input type="text" name="MyField"/&gt;
  </code></pre>
  
  <p>Submit without a value:</p>
  
  <pre><code>public ActionResult MyAction(MyModel model)
  {
      // do stuff
  }
  
  public class MyModel
  {
      public int MyField { get; set; }
  }
  </code></pre>
  
  <p>The property <code>MyField</code> should be allowed to retain its default value of <code>0</code> seeing as an empty value was posted from the form.</p>
  
  <p>Assume that I can't simply change the property type a <code>Nullable&lt;int&gt;</code>.</p>