c# - How are Validation Messages transmitted from controller to view? -


i needed modify validation message on website. reason (maybe bad) took shortcut. going code custom modelbinder. still, expose problem.

in view file, added several hidden input fields , using model binder, in controller, gets 2 entities (one model of view file, other 1 created via hidden input fields)

<input type="text"   name = "fromhiddeninputs.name" value="" /> <input type="hidden" name ="fromhiddeninputs.id" value="0" /> 

note fromhiddeninputs not part of @model.

[httppost] [validateantiforgerytoken] public actionresult create(entity mymodel, secondentity fromhiddeninputs) {     if (modelstate.isvalid){ 

in debug mode on method deals posted result of form. when @ modelstate, see validation errors both entities.

so in view file, using code, can display validation message :

@html.validationmessagefor(model => model.myproperty) 

or

@html.validationmessage("fromhiddeninputs.name", "*") 

so question following, how errors , validation of modelstate passed actionresult viewfile ?

since validation process performed earlier modelbinder, errors data exists in modelstate.values.

now validationmessagefor helper method has extract data it's viewdata.modelstate.values collection.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -