title: How do I disable model validation on a single field in C# MVC?
body: <p>I have a view model that looks vaguely like:</p>
  
  <pre><code>public DateTime StartDate { get; set; }
  public DateTime EndDate { get; set; }
  </code></pre>
  
  <p>I have a custom ModelBinder to parse the fields in the form, and assign the values to them. Which works.</p>
  
  <p>However, when an error occurs, my ModelState ends up with two errors in it. The first from my ModelBinder, and the second from (I guess) the default validation rules:</p>
  
  <pre class="lang-none prettyprint-override"><code>- Invalid start date selected                    &lt;-- My custom error message.
  - The value 'fgfdg' is not valid for Start Date. &lt;-- I want this to go away
  </code></pre>
  
  <p>How do I turn the default validation off for a specific field, on the server side?</p>
  
  <p>Edit: Before you ask, yes my ModelBinder <em>is</em> extending DefaultModelBinder, but obviously I need the other default model binding behaviour; it's just these fields I want a custom behavior for.</p>
  
  <p>(Why don't I just use standard validation rules? Because this is a search form, and depending on if the 'custom date range' is selected, we either ignore the StartDate and EndDate, or parse and perform various checks on them. Specifically, it is an absolute requirement that if the date ranges are invalid (eg. 'fdafsfsf' for start date, but 'search by XXX' instead of 'search by date range' is selected, the form must submit successfully without error)</p>
  
  <p>Code fragment:</p>
  
  <pre><code>[ModelBinderType(typeof(MyViewModel))]
  public class MyViewModelBinder : DefaultModelBinder {
      public override object BindModel(ControllerContext cc, ModelBindingContext bc) {
          var model = new MyViewModel();
          var searchType = cc.HttpContext.Request["SearchType"];
          if (searchType == "CustomDateRange") {
            // Do checks here, etc.
            // ONLY if searchType == "CustomDateRange" should there be ANY validation on StartDate
            bc.ModelState.AddModelError("StartDate", "Invalid start date; outside of invoice range");
          }
          // bc.ModelState["StartDate"].Errors.Clear(); &lt;--- Clears my error, not the default one.
          bc.ModelMetadata.Model = model;
          return base.BindModel(cc, bc); 
      }
  }
  </code></pre>