I've typically done this using edmx's but this time in order to use cascading drop downs in my project I had to switch to use linq to sql.
Anyway here is what I've tried
[HttpPost]
public ActionResult Modules(ModuleViewModel mvm, FormCollection fc)
{
AllCourseDetail ACD = _dc.AllCourseDetails.Where(x => x.IdACD == mvm.cd.IdACD).FirstOrDefault();
ACD = mvm.cd;
if (ModelState.IsValid)
{
UpdateModel(mvm);
_dc.AllCourseDetails.Where(w => w.IdACD == mvm.cd.IdACD);
UpdateModel(mvm.cd);
_dc.SubmitChanges();
Session.Add("redirectedEditcompletedsubmission", "yes");
return RedirectToAction("List");
}
else
{
Session.Add("redirectedEditvalidation", "yes");
return RedirectToAction("Index", "Home");
}
}
At 1st I didn't have anything above the if statement and inside I only had updatemodel and submit changes but no matter what combination I try it just doesn't save.
Also mvm.cd is the AllCourseDetail table which is referenced in the viewmodel as cd and I have to use a view model as
_dc.AllCourseDetails.Where(w => w.IdACD == mvm.cd.IdACD);It appears to be a Linq statement, but the output isn't assigned to anything. Have a look here: stackoverflow.com/a/1427970