Monday, December 31, 2018

I had a coworker struggle with MVC's required attribute today.

[Required(ErrorMessage = "Acknowledgement of the Privacy Policy is required")]

 
 

...would show the default "The Name field is required" instead of "Acknowledgement of the Privacy Policy is required" and in attempting to help I looked at this and this and was ultimately no help. We tried jamming...

data-valmsg-replace="false"

 
 

...inline in the label to no avail. This just made neither error message show up. As this was for a checkbox we also tried:

[BooleanMustBeTrue(ErrorMessage="Acknowledgement of the Privacy Policy is
      required")]

 
 

...but no dice. Eventually, my coworker told me the inline solution was:

data-rule-required="true" data-msg-required="message"

No comments:

Post a Comment