title: Edit Method in MVC4 and Visual Studio 2012
body: <p>Could someone please help me with the question i posted late last night. I am still stuck with the edit method. Link below:</p>
  
  <p><a href="https://stackoverflow.com/questions/12949409/how-to-write-an-edit-action/12949879#comment17556226_12949879">Last night question</a></p>
  
  <p>In addition to what was posted, i have also tried:</p>
  
  <p>HttpPost Edit:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Edit(MensPlayer mensPlayer)
      {
          if (ModelState.IsValid)
          {
              //Save Player
              _dataSource.Entry(mensPlayer).State = EntityState.Modified;
             _dataSource.Save();
  
             TempData["message"] = string.Format("{0} has been saved", mensPlayer.Name);
              return RedirectToAction("Detail", "MensPlayer", new {id = mensPlayer.Id});
          }
          return View(mensPlayer);
      }
  </code></pre>
  
  <p>The Issue with the above method is around <code>Entry(mensPlayer).State</code>, code will not build at .Entry() and i don't seem to know where this method is being inherited. Mind you, this is the technique used in MVC-Music-Store sample.</p>
  
  <p>I have also tried this technique from Pro ASP.NET MVC3 Framework book.</p>
  
  <pre><code>[HttpPost]
      public ActionResult Edit(MensPlayer mensPlayer)
      {
          if (ModelState.IsValid)
          {
              //Save Player
             _dataSource.Save();
  
             TempData["message"] = string.Format("{0} has been saved", mensPlayer.Name);
              return RedirectToAction("Detail", "MensPlayer", new {id = mensPlayer.Id});
          }
          return View(mensPlayer);
      }
  </code></pre>
  
  <p>This technique builds but doesn't seem to save changes to the database.</p>
  
  <p>How can i make it work? What am i missing?</p>
  
  <p><strong>The entire source code is on GitHub if anyone needs to look at the entire solution.</strong></p>
  
  <p><a href="https://github.com/komengem/GlobalUnitedSC" rel="nofollow noreferrer">GitHub</a></p>
  
  <p>With Slauma's help below i have now modified as follows:</p>
  
  <p>Added <code>void Update();</code> to IDataSource and added the following to the Db class</p>
  
  <pre><code> void IDataSource.Update()
      {
          Entry(MensPlayers).State = EntityState.Modified;
      }
  </code></pre>
  
  <p>HttpPost Edit:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Edit(MensPlayer mensPlayer)
      {
          if (ModelState.IsValid)
          {
              //Save Player
              _dataSource.Update();
             _dataSource.Save();
  
             TempData["message"] = string.Format("{0} has been saved", mensPlayer.Name);
              return RedirectToAction("Detail", "MensPlayer", new {id = mensPlayer.Id});
          }
          return View(mensPlayer);
      }
  </code></pre>
  
  <p>All builds but then i get this error
  <strong>The entity type DbSet`1 is not part of the model for the current context.</strong></p>
  
  <p>Which is believed to originate from:</p>
  
  <pre><code>void IDataSource.Update()
      {
          Entry(MensPlayers).State = EntityState.Modified;
      }
  </code></pre>