c# - ASP.Net MVC entity framework submit model, then open new model in edit page -
i've got form submits model. controller saves model database, creates new model , returns editcreate view new model.
the problem i'm having new model isn't being displayed. instead model posted shown. follow through debugger view , see values new, when page displays, shows old values submitted.
controller
[httppost] public actionresult addproduct(myentitymodel mymodel) { // save if (mymodel.id != 0) { update(mymodel); } else { add(mymodel); } modelstate.clear(); // fixed // show page new model myentitymodel newmodel = new myentitymodel(); newmodel.id = 0; // edit/create page actionresult ret = editcreaterow(newmodel); return ret; }
model
public partial class stm_auditdata { public int id { get; set; } public nullable<system.datetime> servicedate { get; set; } public string product { get; set; } }
view
@html.labelfor(model => model.servicedate) @html.editorfor(model => model.servicedate) @html.labelfor(model => model.product) @html.editorfor(model => model.product) @html.hiddenfor(model => model.auditid)
what can ensure correct model shows? thanks.
here's code editcreaterow
public actionresult editcreaterow(myentitymodel row) { myentitymodel.intstobools(ref row); editcreate_setviewbagitems(row); return view("~/views/myentitymodel/editcreate.cshtml", row); }
the reason case, how htmlhelper works. when setting value in html-element, has several options value, using implementations of ivalueprovider. can check default list @ aspnetwebstack. compared better mvc frameworks out there, asp.net mvc counter-intuitive.
if add
modelstate.clear()
before returning, think might have solved.
Comments
Post a Comment