I am trying to learn MVC development and I am following a tutorial for creating a simple movie application located here - Create a Movie Database Application in 15 Minutes with ASP.NET MVC (C#)
Here are my Edit actions -
public ActionResult Edit(int id)
{
var movieToEdit = (from m in _db.Movies
where m.Id == id
select m).First();
return View(movieToEdit);
}
// POST: Home/Edit/5
[HttpPost]
public ActionResult Edit(Movie movieToEdit)
{
try
{
// TODO: Add update logic here
var originalMovie = (from m in _db.Movies
where m.Id == movieToEdit.Id
select m).First();
if (!ModelState.IsValid)
return View(originalMovie);
//_db.Entry(movieToEdit).State = System.Data.Entity.EntityState.Modified;
_db.Entry(movieToEdit).State = EntityState.Modified;
_db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
The guide calls for a line that states _db.ApplyPropertyChanges(originalMovie.EntityKey.EntitySetName, movieToEdit);, however it appears 'ApplyPropertyChanges' is obsolete. I tried using the line that is commented before I added a reference to the System.Data.Entity namespace.
When I run my app, I try to edit a field for one of the rows in the database, but nothing happens when I click the update button. I have a feeling it has something to do with that line that's now deprecated in the tutorial.