title: ModelState.IsValid is always true
body: <p>As is typical in MVC, I have a View, a Model, and a Controller.</p>
  
  <p>The View contains a form:</p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
      @Html.HiddenFor(m =&gt; m.Id)
      &lt;ul class="fieldlist"&gt;
          &lt;li&gt;
              @Html.LabelFor(m =&gt;m.Email)
              @Html.TextBoxFor(m =&gt; m.Email)
              @Html.ValidationMessageFor(m =&gt; m.Email)
          &lt;/li&gt;
          &lt;li&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      @Html.LabelFor(m =&gt; m.FirstName)
                      @Html.TextBoxFor(m =&gt; m.FirstName)
                      @Html.ValidationMessageFor(m =&gt; m.FirstName)
                  &lt;/div&gt;
                  &lt;div class="col-md-6"&gt;
                      @Html.LabelFor(m =&gt; m.LastName)
                      @Html.TextBoxFor(m =&gt; m.LastName)
                      @Html.ValidationMessageFor(m =&gt; m.LastName)
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/li&gt;
          &lt;li&gt;
              @Html.LabelFor(m =&gt; m.PhoneNumber)
              @Html.TextBoxFor(m =&gt; m.PhoneNumber)
              @Html.ValidationMessageFor(m =&gt; m.PhoneNumber)
          &lt;/li&gt;
          &lt;li&gt;
              &lt;div Class="row"&gt;
                  &lt;div Class="col-md-2"&gt;
                      &lt;input type="submit" value="Save" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  }
  </code></pre>
  
  <p>The model looks like this:</p>
  
  <pre><code>public class UserAdminUserViewModel
  {
      [Display(Name = "User Database ID"), DataType(DataType.Text)]
      public string Id { get; set; }
      [Display(Name = "Full Name")]
      public string Name { get { return FirstName + " " + LastName; } }
      [Required()]
      [Display(Name = "First Name"), DataType(DataType.Text)]
      public string FirstName { get; set; }
      [Required()]
      [Display(Name = "Last Name"), DataType(DataType.Text)]
      public string LastName { get; set; }
      [Required()]
      [Display(Name = "Email Address"), DataType(DataType.EmailAddress)]
      public string Email { get; set; }
      [Display(Name = "Telephone Number"), DataType(DataType.Text)]
      public string PhoneNumber { get; set; }
  }
  </code></pre>
  
  <p>And the controller to receive the updates:</p>
  
  <pre><code>[HttpPost,ValidateAntiForgeryToken]
  public ActionResult User(UserAdminUserViewModel model)
  {
      if (ModelState.IsValid)
      {
          // do something, apply the updates to the database, presumably
      }
      return View(model);
  }
  </code></pre>
  
  <p>...but ModelState.IsValid is <em>always</em> true. The controller <em>is</em> receiving the entered information, but it appears that no validation is taking place. I have tried:</p>
  
  <pre><code>TryUpdateModel&lt;UserAdminUserViewModel&gt;(model);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>UpdateModel&lt;UserAdminUserViewModel&gt;(model);
  </code></pre>
  
  <p>I'm not sure I see how these would work, but they were the first suggestions I came across. No dice. Still valid regardless of the data in 'model'. I also tried:</p>
  
  <pre><code>System.ComponentModel.DataAnnotations.Validator.ValidateObject(model, new System.ComponentModel.DataAnnotations.ValidationContext(model));
  </code></pre>
  
  <p>More promising, but still doesn't work. I also tried the more verbose approach:</p>
  
  <pre><code>System.ComponentModel.DataAnnotations.ValidationContext valContext = new System.ComponentModel.DataAnnotations.ValidationContext(model, null, null);
  List&lt;System.ComponentModel.DataAnnotations.ValidationResult&gt; valResults = new List&lt;System.ComponentModel.DataAnnotations.ValidationResult&gt;();
  System.ComponentModel.DataAnnotations.Validator.TryValidateObject(model, valContext, valResults, true);
  foreach(System.ComponentModel.DataAnnotations.ValidationResult result in valResults)
  {
      this.ModelState.AddModelError(result.MemberNames.FirstOrDefault() ?? string.Empty, result.ErrorMessage);
  }
  </code></pre>
  
  <p>...which also didn't work. 'valResults', which should contain any errors in the state of the model, is never filled; no validation is happening.</p>