Entity update from ASP.NET MVC page with post to Edit action
Posted
by mare
on Stack Overflow
See other posts from Stack Overflow
or by mare
Published on 2010-03-14T22:23:30Z
Indexed on
2010/03/14
23:25 UTC
Read the original article
Hit count: 220
asp.net-mvc
|entity-framework
I have a form that posts back to /Edit/ and my action in controller looks like this:
//
// POST: /Client/Edit
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Client client)
My form includes a subset of Client entity properties and I also include a hidden field that holds an ID of the client. The client entity itself is provided via the GET Edit action.
Now I want to do entity update but so far I've only been trying without first loading the entity from the DB. Because the client object that comes in POST Edit has everything it needs. I want to update just those properties on the entity in datastore.
So far I've tried with Context.Refresh() and AttachTo() but with no success - I'm getting all sorts of exceptions. I inspected the entity object as it comes from the web form and it looks fine (it does have an ID and entered data) mapped just fine.
If I do it with Context.SaveChanges() then it just inserts new row..
© Stack Overflow or respective owner