title: Can I automatically trigger model validation inside a custom model binder?
body: <p>I have a complex object that I'm binding off of a form.  The model binder looks like this:</p>
  
  <pre><code>public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
  {
      var form = new MyForm();
  
      var myObject = ...; //try to load up the object
  
      /* logic to populate values on myObject */
      form.MyObject = myObject;
  
      bindingContext.ModelState.SetModelValue(bindingContext.ModelName, new ValueProviderResult(form, "", CultureInfo.CurrentUICulture));
      return form;
  }
  </code></pre>
  
  <p>and it is doing what it's supposed to; I get a correctly populated <code>MyForm</code> out of it, and a reference to the same MyForm instance is included in the ModelState.  However, the form does not get validated using either the <code>DataAnnotations</code> or my <code>CustomValidation</code> validation.  In order to cause that validation, I have to add a <code>TryValidateModel()</code> call in my Controller:</p>
  
  <pre><code>[HttpPost]
  public ActionResult ProcessMyForm(MyForm form)
  {
      //ModelState has the MyForm instance inside of it
      //TryValidateModel(ModelState); //this does not work
      TryValidateModel(form); //this works
      if (!ModelState.IsValid)
      {
          return View("Complete", form);
      }
      return RedirectToAction("Index");
  }
  </code></pre>
  
  <p>Which not only calls into my custom validation, but also updates the value of ModelState.IsValid.</p>
  
  <p>In addition to my title question, this raises a couple of questions:</p>
  
  <ol>
  <li><p>Why does <code>TryValidateModel(ModelState)</code> not validate the form when <code>ModelState</code> has a reference to the same instance of the form that <code>TryValidateModel(form)</code> correctly validates?</p></li>
  <li><p>Why does <code>TryValidateModel(form)</code> cause the value of <code>ModelState.IsValid</code> to be updated?</p></li>
  <li><p>In general, why are the binders responsible for updating <code>ModelState</code>?</p></li>
  </ol>