title: asp.NET MVC 2 DataAnnotations UpdateModel<T> validation
body: <p>I'm trying to use DataAnnotations to add validation to my models in asp.NET MVC 2 RC2, using TryUpdateModel</p>
  
  <pre><code>        var user = UserManager.Find(id);
  
          this.TryUpdateModel&lt;IProvisioningObject&gt;(user, form.ToValueProvider());
  </code></pre>
  
  <p>This updates the model, but the validation is never called. I tried using TryUpdateModel as well (which is the direct type of user), not using the form value provider, using ProvisioningObject directly (which has the validation metadata), to no avail.</p>
  
  <p>Googling for examples only gives me ways to use DataAnnotations by binding through a parameter</p>
  
  <pre><code>public ActionResult Update(User user)
  </code></pre>
  
  <p>Which I dislike for update scenarios.</p>
  
  <p>Any tips and/or solutions?</p>
  
  <p><strong>EDIT</strong>
  My objects are auto-generated objects from a WCF service.</p>
  
  <p>I made partials to be able to add DataAnnotations.
  I call TryUpdateModel three times because it apparently doesn't support inheritance, which I think is also my problem with DataAnnotations. I specify the validation attributes for ProvisioningObject, and the binding doesn't look for inherited stuff like that.</p>
  
  <pre><code>[MetadataType(typeof(ProvisioningObjectMetadata))]
  public partial class ProvisioningObject : IProvisioningObject
  {
      public string DisplayNameInvariant { get { return string.IsNullOrEmpty(this.DisplayName) ? this.Name : this.DisplayName; } }
  }
  
  
  [MetadataType(typeof(UserMetadata))]
  public partial class User : IUser
  {
  }
  
  
  public class ProvisioningObjectMetadata
  {
      [DisplayName("Country")]
      public string CountryIsoCode { get; set; }
  
      [Required(ErrorMessageResourceType = typeof(Properties.Validation), ErrorMessageResourceName = "DisplayNameIsRequired")]
      [TempValidator]
      public string DisplayName { get; set; }
  }
  
  
  public class UserMetadata
  {
      [DisplayName("Username")]
      public string Name { get; set; }
  }
  
  
  // Controller action
      public ActionResult Update(string id, FormCollection form)
      {
          var user = UserManager.Find(id);
  
          this.TryUpdateModel&lt;IUser&gt;(user.User, form.ToValueProvider());
          this.TryUpdateModel&lt;IPerson&gt;(user.User, form.ToValueProvider());
          this.TryUpdateModel&lt;IProvisioningObject&gt;(user.User, form.ToValueProvider());
  
          if (ModelState.IsValid) // always true
          {
              return Redirect;
          }
          else
          {
              return View();
          }
      }
  </code></pre>
  
  <p>If I add the metadata for DisplayName in UserMetadata, it works as expected, but that seems very redundant for nothing. And it would mean I would also have to copy/paste all my inherited interfaces so TryUpdateModel behaves appropriately.</p>
  
  <p>I guess I'm looking for a way that doesn't require me to copy and paste my validation attributes to inherited classes.</p>