title: UpdateModel not working (MVC)
body: <p>I've been following the nerd dinner tutorial. I branched off to create my own project based on it and I'm having trouble getting UpdateModel to work. It seems pretty complicated so I'll try to explain it in as much detail below.</p>
  
  <p>In ServersController.cs:</p>
  
  <pre><code>public ActionResult Create(FormCollection formValues)
  {
      Server server = new Server();
  
      try
      {
          UpdateModel(server);  &lt;----- This is not working
  
          // server.Name = "testAdd";
          // server.OS = "2008 R2";
  
          serverRepository.Add(server);
          serverRepository.Save();
  
          return RedirectToAction("Details", new { id = server.ServerID });
       }
       catch
       {
       **not important**
       }
  </code></pre>
  
  <p>If I try to use UpdateModel(Server), nothing gets saved to the database table. However, If I comment out that line, and use the commented lines in the code that sets the server.Name and server.OS, this DOES save it to the table. However, any other form input that's being posted doesn't save..</p>
  
  <p>For example, if I explicitly set the server.Name and server.OS as in the code above, but then set other properties such as LastBackedUp and Model through the form, none of the properties set from the form are saved to the database table, nor are they reflected in the "details" view when the page gets redirected.</p>
  
  <p>Here's the code for the "Details" GET method, also in ServersController.cs:</p>
  
  <pre><code>public ActionResult Details(int id)
  {
      Server server = serverRepository.GetServer(id);
      RackInfo rackInfo = rackRepository.GetRack(id);
  
      if (server == null)
          return View("NotFound");
      else
          return View(new ServerDetailViewModel(rackInfo, server));
  }
  </code></pre>
  
  <p>Basically, After the new server is created and saved, it's supposed to load the above "Detail" view, which uses a "ServerDetailViewModel" class to generate some data to pass to the view.</p>
  
  <p>Here's the ServerDetailViewModel() code:</p>
  
  <pre><code>public class ServerDetailViewModel
  {
      public RackInfo RackInfo { get; private set; }
      public Server Server { get; private set; }
      public string Name { get; private set; }
  
      public ServerDetailViewModel(RackInfo rackInfo, Server server)
      {
           Server = server;
           RackInfo = rackInfo;
  
           *more code here that sets stuff*
      }
  }
  </code></pre>
  
  <p>I think my problem has something to do with how my form parameters are passed around.</p>
  
  <p>It seems odd that I can explicitly code in some server properties, and then save those into the database table. But when I try to do anything with UpdateModel, nothing seems to go through. When I use UpdateModel, it will redirect me to the details page, but none of the values I input for the properties seem to appear. Additionally, none of the properties I put in through the form gets saved to the database table.</p>
  
  <p>If any of you have walked through the Nerd Dinner tutorial (<a href="http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx</a>), that's what I've been using. When I got through about halfway, I decided to start a new project that implemented what I was using.</p>
  
  <p>I was initially able to get Create to work, but after adding another separate repository to the controller, the create method broke..</p>
  
  <p>Any input or insight on this would be much appreciated. Please let me know if you need any additional information.</p>
  
  <p>Thanks S.O.!!</p>
  
  <p>EDIT (Including the "Create" Form):</p>
  
  <pre><code>@model PACSSL.Models.ServerFormViewModel
  
  @using (Html.BeginForm())
  </code></pre>
  
  <p>{
      @Html.AntiForgeryToken()</p>
  
  <pre><code>&lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Server&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true)
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.Name, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.Name)
              @Html.ValidationMessageFor(model =&gt; model.Server.Name)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Domain, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(x =&gt; x.Domain, Model.Domain)
              @Html.ValidationMessageFor(model =&gt; model.Domain)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.BackedUp, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(x =&gt; x.BackedUp, Model.BackedUp)
              @Html.ValidationMessageFor(model =&gt; model.BackedUp)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.Role, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.Role)
              @Html.ValidationMessageFor(model =&gt; model.Server.Role)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.GroupOwner, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.GroupOwner)
              @Html.ValidationMessageFor(model =&gt; model.Server.GroupOwner)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.PatchNotes, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.PatchNotes)
              @Html.ValidationMessageFor(model =&gt; model.Server.PatchNotes)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.LastPatched, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.LastPatched) Format: yyyy-mm-dd
              @Html.ValidationMessageFor(model =&gt; model.Server.LastPatched)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.PatchedBy, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(x =&gt; x.PatchedBy, Model.PatchedBy)
              @Html.ValidationMessageFor(model =&gt; model.PatchedBy)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.VP, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(x =&gt; x.VP, Model.VP)
              @Html.ValidationMessageFor(model =&gt; model.VP)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.VMHost, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.VMHost)
              @Html.ValidationMessageFor(model =&gt; model.Server.VMHost)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.Location, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.Location)
              @Html.ValidationMessageFor(model =&gt; model.Server.Location)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.PurchaseDate, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.PurchaseDate) Format: yyyy-mm-dd
              @Html.ValidationMessageFor(model =&gt; model.Server.PurchaseDate)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.OS, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.OS)
              @Html.ValidationMessageFor(model =&gt; model.Server.OS)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.Model, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.Model)
              @Html.ValidationMessageFor(model =&gt; model.Server.Model)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.DellST, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.DellST)
              @Html.ValidationMessageFor(model =&gt; model.Server.DellST)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.ServiceContract, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.ServiceContract) Format: yyyy-mm-dd
              @Html.ValidationMessageFor(model =&gt; model.Server.ServiceContract)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Server.IsLive, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Server.IsLive)
              @Html.ValidationMessageFor(model =&gt; model.Server.IsLive)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>}</p>