title: In MVC, one Edit HttpPost is working, the other one isn't. What am I missing?
body: <p>Googling generally and on SO hasn't helped me yet, so:</p>
  
  <p>I am building my first MVC application from scratch, going by the <a href="http://mvcmusicstore.codeplex.com/" rel="nofollow noreferrer">MVC Music Store example</a> but instead building a little application where arena Fighters can be created and made to Fight each other. (<code>Fighters</code> and <code>Fight</code> have been made linked to underlying tables through EF). </p>
  
  <p>I have controllers for both the <code>Fighters</code> and the <code>Fights</code>. The Edit <code>Actionresult</code> for <code>Fights</code> is working, but for <code>Fighters</code> it is not. When I hit the button to save my alterations I return to the associated Index page, but no changes have been committed. This is my question: why is this failing?</p>
  
  <p>From <strong>BarracksController</strong>, with the faulty non-updating HttpPost Edit (should have been named FighterController, but neverthemind):</p>
  
  <pre><code>        //
          // GET: /Barracks/Edit
          public ActionResult Edit(int id)
          {
              ViewData.Model = _FightDb.Fighters.Single(f =&gt; f.Id == id);
              return View();
          }
  
  
          //
          // POST: /Barracks/Edit
          [HttpPost]
          public ActionResult Edit(int id, FormCollection collection)
          {
              var fighter = _FightDb.Fighters.Single(f =&gt; f.Id == id);
  
              try
              {
                  UpdateModel(fighter, "Fighter");
                  var x = ViewData.GetModelStateErrors();
                  _FightDb.SaveChanges();
  
                  return RedirectToAction("Index");
              }
              catch
              {
                  var viewModel = fighter;
  
                  return View(viewModel);
              }
  
          }
  </code></pre>
  
  <p>(As you can see, I've included <a href="https://stackoverflow.com/questions/2936927/asp-net-mvc-2-updatemodel-is-not-updating-values-in-memory-or-database">the GetModelStateErrors trick from this SO question</a>, but the result for x is <code>null</code>)</p>
  
  <p><strong>This is the controller that does work, FightController:</strong></p>
  
  <pre><code>   //
          // GET: /Fights/Edit
          public ActionResult Edit(int id)
          {
              var viewModel = new FightDetailsViewModel
              {
                  Fight = _FightDb.Fights.Single(f =&gt; f.ID == id),
                  Fighters = _FightDb.Fighters.ToList()
              };
  
              return View(viewModel);
          }
  
          //
          // POST: /Fights/Edit
          [HttpPost]
          public ActionResult Edit(int id, FormCollection collection)
          {
              var fight = _FightDb.Fights.Single(f =&gt; f.ID == id);
  
              try
              {
                  UpdateModel(fight, "Fight");
                  _FightDb.SaveChanges();
  
                  return RedirectToAction("Index");
              }
              catch
              {
                  var viewModel = new FightDetailsViewModel
                  {
                      Fight = _FightDb.Fights.Single(f =&gt; f.ID == id),
                      Fighters = _FightDb.Fighters.ToList()
                  };
  
                  return View(viewModel);
              }
          }
  </code></pre>
  
  <p><strong>This is edit.aspx for the Fighters:</strong> (Edited after comment)</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;Mvc3_EF_BW_Fight.Models.Fighter&gt;" %&gt;
  
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="server"&gt;
      &lt;h2&gt;Edit&lt;/h2&gt;
  
          &lt;%: Html.EditorForModel()  %&gt;
  
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>Which uses the following Fighter.ascx in Shared:</strong></p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;Mvc3_EF_BW_Fight.Models.Fighter&gt;" %&gt;
  &lt;% using (Html.BeginForm())
     {%&gt;
  &lt;%: Html.ValidationSummary(true) %&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;Fighter&lt;/legend&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Id) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.Id) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.Id) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.FighterName) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.FighterName) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.FighterName) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.FighterStyleDescription) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.FighterStyleDescription) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.FighterStyleDescription) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.FighterLongDescription) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextAreaFor(model =&gt; model.FighterLongDescription) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.FighterLongDescription) %&gt;
      &lt;/div&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Save" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p><strong>This is the edit.aspx for Fights</strong></p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;Mvc3_EF_BW_Fight.ViewModels.FightDetailsViewModel&gt;" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="server"&gt;
  
      &lt;h2&gt;Edit&lt;/h2&gt;
      &lt;%: Html.EditorFor(model =&gt; model.Fight, new { Fighters = Model.Fighters })%&gt;
  
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>And this is the Fight.ascx:</strong></p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;Mvc3_EF_BW_Fight.Models.Fight&gt;" %&gt;
  &lt;% using (Html.BeginForm())
     {%&gt;
  &lt;%: Html.ValidationSummary(true) %&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;Fields&lt;/legend&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.ID) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.ID) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.ID) %&gt;
      &lt;/div&gt;
  
  
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.FightName) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.FightName) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.FightName) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Fighter1ID) %&gt;&lt;br /&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Fighter1Reference.Value.FighterName)%&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.DropDownList("Fighter1ID", new SelectList(ViewData["Fighters"] as IEnumerable, "ID", "FighterName", Model.Fighter1ID))%&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.Fighter1ID) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Fighter2ID) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.DropDownList("Fighter1ID", new SelectList(ViewData["Fighters"] as IEnumerable, "ID", "FighterName", Model.Fighter1ID))%&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.Fighter2ID) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Fighter1Login) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.Fighter1Login) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.Fighter1Login) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.Fighter2Login) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.Fighter2Login) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.Fighter2Login) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;%: Html.LabelFor(model =&gt; model.FightStatusID) %&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;%: Html.TextBoxFor(model =&gt; model.FightStatusID) %&gt;
          &lt;%: Html.ValidationMessageFor(model =&gt; model.FightStatusID) %&gt;
      &lt;/div&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Save" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p><strong>And this is my viewmodel for Fights:</strong></p>
  
  <pre><code>public class FightDetailsViewModel
  {
      public Fight Fight { get; set; }
      public List&lt;Fighter&gt; Fighters { get; set; }
  }
  </code></pre>
  
  <p>There is no ViewModel for Fighters (none that is involved in this scenario, anyway).</p>
  
  <p>I can post any code you may wish to see.</p>
  
  <p>Edit: I've looked at <a href="https://stackoverflow.com/questions/2160171/using-viewmodel-pattern-with-mvc-2-strongly-typed-html-helpers">Using ViewModel Pattern with MVC 2 Strongly Typed HTML Helpers</a> and <a href="https://stackoverflow.com/questions/2936927/asp-net-mvc-2-updatemodel-is-not-updating-values-in-memory-or-database">ASP.NET MVC 2 UpdateModel() is not updating values in memory or database</a> , but i haven't seen a solution there yet.</p>