asp.net mvc 5 - MVC5 Unused model fields are lost between GET and POST -


if respond populating model object initialization data (like current username), , no editor field used in view, when form posts, field nulled out. appears true if use displayfor or lablefor well.

example:

       //changeaccountinfo        [authorize]        public actionresult changesecurityqa() {            changesecurityqamodel qa = new changesecurityqamodel(@user.identity.name);             //this constructor sets username , loads several other fields necessary process.           return view(qa);        }          //        //changesecurityqa post        [httppost]        [authorize]        public actionresult changesecurityqa(changesecurityqamodel imodel) {             \\imodel.username null...         } 

the view in question not use username, methods call in post handler will.

for username thats not big deal again, info more complicated flow, how can ensure information entered model controllers come post?

that data has exist in form somewhere. if there's no field it, add hidden one:

@html.hiddenfor(x=> x.somefield) 

the controller can't pass information directly 1 action another. information needs exist on de-serialized model in target action needs de-serialized http request, means has in form post.

be aware, of course, users can see , edit value. that's sensitive shouldn't sent user, , comes user should validated.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -