asp.net - Html.ValidationSummary showing duplicate error messages -


i have searched , googled answer question no avail. i'm using ef4 , asp.net mvc2 , have ef4 entity "award" non-nullable string field, "recipientid". i'm using dataannotations server-side validation, in "award" partial class i've set recipientid have required attribute. when try submit form recipientid text box empty, see error message "please enter recipient" in html.validationsummary twice.

would because error being thrown both entity (in non-nullable field null value), application? whatever reason, there way "fix" , have error message show once? (fix being in quotations because i'm not sure if intended behavior or not.) didn't think necessary include relevant code, if it's needed.

thank in advance help.

it looks intended, according brad wilson. should have searched "constraintexception" , ef4. :)

according brad, input validation fired before model bound resulting in "required" error thrown. in addition, these fields non-nullable, meaning throw same "required" during model-binding. in opinion, it's bit confusing show same message specified in "required" attribute, rather sql exception message, since makes same error. not. that's constraintexception comes in. in order prevent duplicate messages, wrap model-binding code so:

if (modelstate.isvalid) {     validatemodel(award);     repository.add(award);     repository.save(); } 

simple that. thanks!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -