I'm using Ajax binding, and my Destroy method looks like this:
An object with a temporary EntityKey value cannot be attached to an object context
Any idea why this is? What am I doing wrong?
[HttpPost]However this code fails with the error:
public ActionResult AjaxDelete([DataSourceRequest]DataSourceRequest request, tbl_app_Customer customerToDelete) {
if (customerToDelete != null) {
db.tbl_app_Customer.Attach(customerToDelete);
db.ObjectStateManager.ChangeObjectState(customerToDelete, EntityState.Deleted);
db.SaveChanges();
}
return Json(ModelState.ToDataSourceResult());
}
An object with a temporary EntityKey value cannot be attached to an object context
Any idea why this is? What am I doing wrong?