title: MVC - Partially update the model in the view
body: <p>Heres the scenario: I have a User object like this:</p>
  
  <pre><code> public class User : BaseEntity&lt;User&gt;, IAggregateRoot
   {
      public virtual string Name { get; set; }
      public virtual string Username { get; set; }
      public virtual string Password { get; set; }
      public virtual string SecretQuestion { get; set; }
      public virtual string SecretAnswer { get; set; }
      public virtual DateTime LastLogin { get; set; }
   }
  </code></pre>
  
  <p>During the editing of this object, i load it into the view, but i only want to update some of the properties (ie i wouldnt want to update LastLogin property). In this situation what would i do? </p>
  
  <p>Is the best strategy to create a user viewmodel, and will nhibernate cope with this when i try to update a user object with a null LastLogin field?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Something like this:</p>
  
  <pre><code>public class UserViewModel
  {
    public string Name {get;set;}
    public string UserName {get;set;}
    public string Password {get;set;}
    public string SecretQuestion {get;set;}
    public string SecretAnswer {get;set;}
  }
  </code></pre>
  
  <p>And then the editing:</p>
  
  <pre><code>public ActionResult Edit(int id)
  {
    return View(_userRepository.FindById(id));
  }
  
  [HttpPost]
  public ActionResult Edit(int id, UserViewModel userViewModel)
  {
    try
    {
  
      //Not sure how to update the model 
      //with the view Model and save.
  
      _userRepository.Update(????);
      return RedirectToAction("Index");
    }
    catch
    {
      return View();
    }
  }
  </code></pre>