asp.net mvc 4 - I need to update the model view and reflect those changes in database -
here,i have typed view in i'm showing registered user his/her data in form allow updating edited data , make changes reflected database.
i have written code action methods in both , post method accordingly can't figure out what's causing issue.the issue changes made on view page binded model class not reflected database table though have written method db.submit changes().
below code: , post action methods detailsupdate view page:
[httppost] [validateantiforgerytoken] public actionresult patientdetailspage2(patients p) { if (modelstate.isvalid) { tblpatient updatedpatientdetail = new tblpatient() { patientname = p.patientname, patientage = (short) p.age, patientmail = p.patientemail, patientmobileno = p.patientmobileno, patientpassword = p.patientpassword }; db.submitchanges(); return view(); } else { viewbag.errormessage = "please ensure fields filled correctly"; } return view(); } public actionresult patientdetailspage2() { if(tempdata["doc"] != null) { var data = (patients)tempdata["doc"]; return view(data); } return view(); }
also mention when place debug , scan updated values shows updated value @ point model's object assigned table parameters submit changes line code scanned shows old value password field(the field value want updated here).please me programmers!
[httppost] [validateantiforgerytoken] public actionresult patientdetailspage2(patients p) { if (modelstate.isvalid) { tblpatient updatedpatientdetail = new tblpatient() { patientname = p.patientname, patientage = (short) p.age, patientmail = p.patientemail, patientmobileno = p.patientmobileno, patientpassword = p.patientpassword }; db.patients.add(updatedpatientdetail); db.submitchanges(); return view(); } else { viewbag.errormessage = "please ensure fields filled correctly"; } return view(); }
you must add model object db model before save.
Comments
Post a Comment