title: ASP.NET MVC - How exactly to use View Models
body: <p>Let's say I have a page that allows the editing of a user's details, so I have a ViewModel like this:</p>
  
  <pre><code>public class UserViewModel {
      public string Username { get; set; }
      public string Password { get; set; }
      public int ManagerId { get; set; }
      public string Category { get; set; }
  }
  </code></pre>
  
  <p>So on my EditUser action I can have this passed back by the model binder and then I can map that to the Domain Model:</p>
  
  <pre><code>public ActionResult EditUser(UserViewModel user) {
      ...
  </code></pre>
  
  <p>However, the page that displays the form also needs details such as a list of Managers and Categories to provide dropdowns for those fields.  It might also display a list of other users in a sidebar so you can switch between the different users you're editing.</p>
  
  <p>So then I have another view model:</p>
  
  <pre><code>public class ViewUserViewModel {
      public UserViewModel EditingUser { get; set; }
      public IEnumerable&lt;SelectListItem&gt; Managers { get; set; }
      public IEnumerable&lt;SelectListItem&gt; Categories { get; set; }
      public IEnumerable&lt;SelectListItem&gt; AllUsers { get; set; }
  }
  </code></pre>
  
  <p>Is this the correct way to do it?  Are they both View Models?  If so, is there a naming convention I should use so I can distinguish between VMs that are like models and VMs that just contain data for the page?</p>
  
  <p>Have I got this all wrong?</p>