If i am using adding , then it's add new row, but i want to update row data.when using modified then on DB.SaveChanges() it showing exception.Means i am not able to update.
OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.
[HttpPost]
public ActionResult EditCategory(int id,tbl_Category category, HttpPostedFileBase file)
{
tbl_Category ctgry = new tbl_Category();
if (file != null && file.ContentLength > 0)
try
{
string folderpath = Server.MapPath("~/Images/category_Images");
string filename = Path.GetFileName(file.FileName);
string extension = Path.GetExtension(file.FileName);
string path = Path.Combine(Server.MapPath("~/Images/category_Images"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
ctgry.Image = filename;
}
catch { }
ctgry.CategoryName = category.CategoryName;
ctgry.Status = category.Status;
DB.Entry(ctgry).State = EntityState.Modified;
//DB.Entry(ctgry).State = EntityState.Added;
DB.SaveChanges();
return RedirectToAction("Category");
}