Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Participant
922 Points
871 Posts
Apr 29, 2012 08:00 PM|LINK
thanks for the reply; i update my EditPOST action method to:-
[HttpPost] public ActionResult Edit([Bind(Include = "Note,DoctorID,VisitID,StatusID,timestamp")] Visit visit) //[Bind(Include="Note,DoctorID,VisitID,StatusID")] { if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name))) { try { if (ModelState.IsValid) { int id = visit.VisitID; var v = repository.GetVisit(id); visit.CreatedBy = v.CreatedBy; visit.Date = v.Date; visit.PatientID = v.PatientID; visit.VisitTypeID = v.VisitTypeID; repository.UpdateVisit(visit); repository.Save(); return RedirectToAction("Index"); } } catch (DbUpdateConcurrencyException ex) { //code goes here
and the repository.UpdateVisit(visit); code looks like:-
public void UpdateVisit(Visit v) { entities.Entry(v).State = EntityState.Modified; }
But when i run my application and i try to edit the visit object i got the following error :-
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.
on the repository.UpdateVisit(visit) Method; so what are going wrong? BR
johnjohn1231...
Participant
922 Points
871 Posts
Re: Security Concern when Editing an object using asp.net MVC model binder
Apr 29, 2012 08:00 PM|LINK
thanks for the reply; i update my EditPOST action method to:-
[HttpPost] public ActionResult Edit([Bind(Include = "Note,DoctorID,VisitID,StatusID,timestamp")] Visit visit) //[Bind(Include="Note,DoctorID,VisitID,StatusID")] { if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name))) { try { if (ModelState.IsValid) { int id = visit.VisitID; var v = repository.GetVisit(id); visit.CreatedBy = v.CreatedBy; visit.Date = v.Date; visit.PatientID = v.PatientID; visit.VisitTypeID = v.VisitTypeID; repository.UpdateVisit(visit); repository.Save(); return RedirectToAction("Index"); } } catch (DbUpdateConcurrencyException ex) { //code goes hereand the repository.UpdateVisit(visit); code looks like:-
public void UpdateVisit(Visit v) { entities.Entry(v).State = EntityState.Modified; }But when i run my application and i try to edit the visit object i got the following error :-
on the repository.UpdateVisit(visit) Method; so what are going wrong? BR