Hello,
I am new in MVC.
I am getting one problem. I am editing the record from the following code :
public ActionResult Edit(int id)
{
using (var db = new TestEntities())
{
return View(db.DepartmentMasters.Find(id));
}
}
[HttpPost]
public ActionResult Edit(int id, DepartmentMaster dm)
{
try
{
using (var db = new TestEntities())
{
db.Entry(dm).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
Now when
public ActionResult Edit(int id)
this function is call i get the id . But when i edit the record and call this method
public ActionResult Edit(int id, DepartmentMaster dm)
, i get the ID value 0, so i am not able to edit the record.
i am getting the following error:
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.