Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am working on MVC 3, I am trying to delete a record from the table, but when I click on the delete button I am getting the following error at the "test.Savechanges();" from the below code.

SQL
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.



This is my controller code:

C#
public ActionResult Delete(tblEmployee viwEmp)
{
   test.Entry(viwEmp).State = System.Data.EntityState.Deleted;
   test.SaveChanges();
   return RedirectToAction("CRUDS");
}
Posted
Comments
CBadger 7-Mar-14 2:38am    
Does the controller pass an ID value if you step into a break point?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900