title: ASP.NET MVC 2 edit controller doesn't work using viewmodel
body: <p>Hey, the problem is that edit controller in ASP.NET MVC 2 doesn't work. I tried many ways and nothing works.</p>
  
  <p>Here's a sample code:</p>
  
  <pre><code>[Authorize]
  public ActionResult Edit() {
      var edit = new UserViewModel {
          User = Database.Users.Single(u =&gt; u.UserName == User.Identity.Name)
      };
  
      return View(edit);
  }
  
  [Authorize]
  [HttpPost]
  public ActionResult Edit(FormCollection formCollection) {
      var edit = new UserViewModel {
          User = Database.Users.Single(u =&gt; u.UserName == User.Identity.Name)
      };
  
      // TODO: try, catch
      UpdateModel(edit, "User");
      Database.SaveChanges();
  
      return View(edit);
  }
  </code></pre>
  
  <p>Here's a view model class:</p>
  
  <pre><code>public class UserViewModel {
      public User User { get; set; }
  }
  </code></pre>
  
  <p>What should I do to update this user model to database? A the moment I'm using only Email field:</p>
  
  <pre><code>&lt;% Html.EnableClientValidation(); %&gt;
  &lt;% using (Html.BeginForm()) {%&gt;
  &lt;div&gt;
      &lt;div class="UserFieldLeft"&gt;&lt;%: Html.LabelFor(model =&gt; model.User.Email) %&gt;&lt;/div&gt;
      &lt;div class="UserFieldRight"&gt;&lt;%: Html.TextBoxFor(model =&gt; model.User.Email, new { style="width: 200px" }) %&gt;&lt;/div&gt;
      &lt;div class="UserFieldHelper"&gt;&lt;%: Html.ValidationMessageFor(model =&gt; model.User.Email) %&gt;&lt;/div&gt;
      &lt;p&gt;&lt;input class="UserFieldInput" type="submit" value="Zmień email" /&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>If I work on native user model it doesn't work too. What's wrong? Where did I made a mistake?</p>
  
  <p>By the way, I've to use view model to add (in future) some checkboxes (hair color, length, etc.) to my user.</p>
  
  <p>Thank you for your time and help.</p>