I have the following code – truck_mng is a record that as the data I need to update:
public ActionResult Edit(Truck_Mng truck_mng)
{
if (ModelState.IsValid)
{
DataContext.SubmitChanges();
return RedirectToAction("Index");
}
return RedirectToAction("index");
}
The record does not get updated. Any idea? The table does have a primary key.
I guess Truck_Mng is an entity class from you DataContext?
You hve to attach the entity first to your DataContext, because the modelbinder of the MVC framework just creates a new instance of that class to pass the form data to your action.
By setting the second parameter to
true, you tell L2S that the entity is in modified state, but that only works when you have a timestamp member for version checking on your entity.The simplest approach wiould be to attach as unmodified and then call
Refresh. That way L2S checks for modifications and you can save your changed: