javascript - AngularJS empty input model after mvc postback -
using angularjs ng-model fields cleared after postback mvc controllers. can prevent somehow , put values postback model? every time user make postback validation error fields cleared because of ng-model. ideas?
@using (html.beginform("register", "account", formmethod.post)) { @html.textboxfor(x => x.register.username, new { @ng_model = "username" }) @html.textboxfor(x => x.register.password, new { @ng_model = "password" }) } [allowanonymous] public actionresult register(registermodel viewmodel) { return view(viewmodel); }
this happens because when angular kicks in, values username , password on $scope null , override set view.
ng-init may solve problem
consider like
@html.textboxfor(x => x.register.username, new { @ng_model = "username", @ng_init = "username ='" + model.register.username + "'" }) @html.textboxfor(x => x.register.password, new { @ng_model = "password", @ng_init = "password ='" + model.register.password + "'" })
cheers
Comments
Post a Comment