title: How to update Model when binding to a ViewModel?
body: <p>I have an <code>[HttpPost]</code> action method signature like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(ExistingPostViewModel model)
  {
     // Save the edited Post.
  }
  </code></pre>
  
  <p>Now, in the past (when i didn't use ViewModels, e.g R&amp;D), i had an implementation of an <strong>Edit</strong> method like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(Post model)
  {
      var existingPost = repo.Find(model.Id);
      TryUpdateModel(existingPost);
      repo.Save(existingPost);  
      return RedirectToAction("Success", existingPost.Id);
  }
  </code></pre>
  
  <p>Which worked great.</p>
  
  <p>But i'm confused how to adapt the above to the ViewModel approach.</p>
  
  <p>If i do this:</p>
  
  <pre><code>TryUpdateModel(existingPost)
  </code></pre>
  
  <p>With my ViewModel approach, not much happens. No errors, but nothing is being updated because MVC won't know how to update a <code>Post</code> from a <code>ExistingPostViewModel</code> (before it was <code>Post</code> -> <code>Post</code>).</p>
  
  <p>Now, i'm using AutoMapper. So i thought i could map from the ViewModel to the <code>Post</code>, then save the post. </p>
  
  <p>But then im basically overriding everything. Which i don't want to do and defeats the point of the cut down ViewModel. </p>
  
  <p>Can anyone un-confuse me?</p>
  
  <p>This seems like a really common scenario, and i am totally stumped as to how people solve this. I can only see 3 possible solutions:</p>
  
  <ol>
  <li><p>Don't use a ViewModel in the HTTP POST. As i said i did this in the past for R&amp;D and it works, but now i see how my View's have evolved (validation, simplicity), and i can't compromise that just for the sake of this problem.</p></li>
  <li><p>Don't use TryUpdateModel. Possibly, but then how would i merge in the changes?</p></li>
  <li><p>Use left-to-right. Ugh. But at the moment this seems to be the way im leaning.</p></li>
  </ol>
  
  <p>Someone please give me solution #4! :)</p>
  
  <p>BTW, i'm using ASP.NET MVC 3, Razor and Entity Framework.</p>