I fixed some code that was giving the same error message when trying to update a record. I had the following code initially:
[HttpPost]
public ActionResult Edit(Project project)
{
if (ModelState.IsValid)
{
entity.Entry(project).State = EntityState.Modified;
entity.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View(project);
}
Instead of the following code
[HttpPost]
public ActionResult Edit(Project project)
{
if (ModelState.IsValid)
{
entity.Entry(project).State = EntityState.Added;
entity.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View(project);
}