Entity update from ASP.NET MVC page with post to Edit action
- by mare
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..