title: Should I annotate my view model or my model?
body: <p>If I am using the MVVM pattern to populate my views, i.e. I am using a View Model in addition to the model classes. The model classes do not talk to the view; the view model populates the view.</p>
  
  <p>In such a scenario, if I need to use data annotations for validation, etc. I need to annotate my view model classes and not my model classes, right?</p>
  
  <p>For e.g. should the [Required] attribute be annotated on:</p>
  
  <pre><code>namespace MyApp.ViewModels
  {
      public class Category
      {
          [Required]
          [StringLength(50)]
          public string CategoryName { get; set; }
  
          [StringLength(255)]
          [AllowHtml]
          public string Description { get; set; }
      }
  }
  </code></pre>
  
  <p>Or should it be this way:</p>
  
  <pre><code>namespace MyApp.Models
  {
      public partial class Category
      {
          [Required]
          public virtual string CategoryName
          {
              get;
              set;
          }
      }
  }
  </code></pre>