can we pass entire model to javascript asp.net mvc -
i have problem on javascript call form submit , model gets updated controller ,but not updating in view. thinking update model new model values in javascript . view shows latest model values can done?
thanks, michael
your question extremely unclear , provided no source code makes things more unclear. various comments may have posted assume trying update model value inside post action without removing model state , when same view rendered again old values displayed.
so suppose have view model looks close this:
public class myviewmodel { public httppostedfilebase file { get; set; } public string somevalue { get; set; } }
and controller:
public class homecontroller : controller { public actionresult index() { var model = new myviewmodel { somevalue = "initial value" }; return view(model); } [httppost] public actionresult index(myviewmodel model) { // notice how somevalue property removed // model state because updating value , // html helpers don't use old value modelstate.remove("somevalue"); model.somevalue = "some new value"; return view(model); } }
and view:
<% using (html.beginform(null, null, formmethod.post, new { enctype = "multipart/form-data" })) { %> <div> <%= html.labelfor(x => x.somevalue) %> <%= html.editorfor(x => x.somevalue) %> </div> <div> <label for="file">attachment</label> <input type="file" name="file" /> </div> <input type="submit" value="ok" /> <% } %>
Comments
Post a Comment