It looks like this snippet of code doesn't work unless I include the first line of the snippet which is not referenced anywhere afterwards? Is this how ApplyCurrentValues
method works?
_entities.Contacts.FirstOrDefault(c => c.Id == contactToEdit.Id);
_entities.Contacts.ApplyCurrentValues(contactToEdit);
_entities.SaveChanges();
return RedirectToAction("Index");
This code edits a contact record and saves to the database.
Here's the entire method:
[HttpPost]
public ActionResult Edit(Contact contactToEdit)
{
if (!ModelState.IsValid)
{
return View();
}
try
{
_entities.Contacts.FirstOrDefault(c => c.Id == contactToEdit.Id);
_entities.Contacts.ApplyCurrentValues(contactToEdit);
_entities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}