I’ve tried several ways to update an object in my database. I’ve also read a couple of questions out here and other forums concerning updating data. But except for one way nothing else is working for me.
What works? If I update all attributes manually it works. Something like this:
[HttpPost]
public ActionResult UpdateModel(Person person)
{
DBEntities db = new DBEntities();
var p = db.PERSON.Single( x=> x.ID == person.ID);
p.NAME = person.NAME;
p.AGE = person.AGE;
db.SaveChanges();
}
But for models with a lot of attributes this isn’t really an option. Is there someway I can do something simular to this?
[HttpPost]
public ActionResult UpdateModel(Person person)
{
DBEntities db = new DBEntities();
var p = db.PERSON.Single( x=> x.ID == person.ID);
p = person;
db.SaveChanges();
}
I know that there are a lot of questions out there similar to mine but i’m just not able to let this to work for me.
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.tryupdatemodel.aspx