ASP.NET MVC & Detached Entity won't save
- by Justin
Hey all,
I have an ASP.NET MVC POST action for saving an entity on submit of a form. It works fine for insert but doesn't work for update, the database doesn't get called, so it's clearly not tracking the changes, as it's "detached". I'm using Entity Framework w/.NET 4:
//POST: /Developers/Save/
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(Developer developer)
{
developer.UpdateDate = DateTime.Now;
if (developer.DeveloperID == 0)
{//inserting new developer.
DataContext.DeveloperData.Insert(developer);
}
//save changes - TODO: doesn't update...
DataContext.SaveChanges();
//redirect to developer list.
return RedirectToAction("Index");
}
Any ideas would be greatly appreciated, thanks,
Justin