this is my first mvc 3 project, i am using linq to sql.
public ActionResult Edit(int ID)
{
try
{
Tutorial tut = reposi.Tutorials.Single(d => d.TutorialID == ID);
return View(tut);
}
catch
{
return RedirectToAction("List");
}
}
[HttpPost]
public ActionResult Edit(Tutorial tut)
{
if (ModelState.IsValid)
{
//tut.TutorialID = ID;
tut.EditDate = DateTime.Now;
tutContext.SubmitChanges();
return RedirectToAction("List");
}
else
{
return View(tut);
}
}
after I click on the “Edit” button, It takes me back to list page, and changes are not saved. still old values.
You need to first get the
Tutorialfrom your database, then make the changes, thenSubmitChanges().Note, your
tutContext.get(tut.Id);may be different depending on your implementation.