title: ASP.Net MVC Controller UpdateModel not updating
body: <p>Trying to get UpdateModel to work for my User.  The User class has basic string properties like CompanyName, FirstName, LastName, etc so nothing exotic.  </p>
  
  <p>Here is the header for my view:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Public.Master" Inherits="System.Web.Mvc.ViewPage&lt;User&gt;" %&gt;
  </code></pre>
  
  <p>After they submit, in my controller, the code looks like this:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Edit(string id, FormCollection collection)
      {
          try
          {
              User myUser = db.Get&lt;IUserRepository&gt;().Get(id);
              UpdateModel(myUser);
              db.Update(myUser);
  
              return RedirectToAction("Index", "Home");
          }
          catch
          {
              return View();
          }
      }
  </code></pre>
  
  <p>The values past into FormCollection have the values like:</p>
  
  <pre><code>[0] "FirstName" string
  [1] "LastName" string
  [2] "Email" string
  </code></pre>
  
  <p>Here is my UserModelBinder (took out some error checking code) which seems to be the source of the problem:</p>
  
  <pre><code>public class UserModelBinder : IModelBinder
  {
      public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          IPrincipal p = controllerContext.HttpContext.User;
          User u = db.Get(p.Identity.Name);
          return u;
      }
  }
  </code></pre>
  
  <p>while the myUser I get from the database has all its original values, the UpdateModel for my controller never actually makes any changes.  I have read problems people have with ViewModels and which prefix to use, but I am just passing in the regular database object.  </p>
  
  <p>The strange thing is that this User edit is for my "Public" area and I already have a User edit for the Admin area which lets the administrator change extra Properties. The "Admin" area User edit is working fine, but the "Public" area for User edit isn't even though the code is almost identical.  </p>
  
  <p>Update:</p>
  
  <p>This turned out to be a custom ModelBinding problem and by changing my UserModelBinding to derive from DefaultModelBinder and adding into my BindModel method:</p>
  
  <pre><code>if (bindingContext.Model != null)
              return base.BindModel(controllerContext, bindingContext);
  </code></pre>
  
  <p>Everything seems to work.</p>