title: In asp.net-mvc, what is causing my model state errors?
body: <p>I am posting a form in an asp.net-mvc page.  Here is my controller action:</p>
  
  <pre><code>    public ActionResult UpdateData(MyFormObject entity)
      {
          bool isValid = IsValid(entity);
  
          if (!isValid)
          {
              var firstError = ModelState.Values.SelectMany(v =&gt; v.Errors).First();
              throw new HttpException(404, firstError.ErrorMessage);
          }
          return Json(BuildResult(entity));
      }
  </code></pre>
  
  <p>Even thought the post passes all of my explicit validation logic, when i check ModelState I see errors.  I am seeing errors in ModelState when any of my properties are empty.  Here is my object:</p>
  
  <pre><code>public class MyFormObject 
  {
      public int Id{ get; set; }
      public int TestId{ get; set; }
      public int OtherId{ get; set; }
  }
  </code></pre>
  
  <p>and I am looking at Model.State and i see errors for any element in my object that is not populated. </p>
  
  <p>If I change this to  (NOTE: the "?")</p>
  
  <pre><code>public class MyFormObject 
  {
      public int? Id{ get; set; }
      public int? TestId{ get; set; }
      public int? OtherId{ get; set; }
  }
  </code></pre>
  
  <p>then i no longer get any errors.  Is there some default validation that is happening here that I am not setting.  I am trying to figure out what is setting ModelState errors in the first case above.</p>