The additional data annotations attributes included in MVC 3 Futures (CreditCard, EmailAddress, FileExtension, Url) do not work when using a Resource File Property. For example, using the attribute [Email(ErrorMessageResourceName = "ErrorMessage",
ErrorMessageResourceType = typeof(Resource1))] fails at runtime with the following error: "Either ErrorMessageString or ErrorMessageResourceName must be set, but not both". This occurs because a default ErrorMessage is being set in the attribute
constructors, so when the user adds a resource error message the FormatErrorMessage() base class method doesn't know which to use. I believe the fix would be to take the default error message out of the constructor and override the FormatErrorMessage() method
of the base class, and augment it by setting the default ErrorMessage only if no message (either a static string or resource file) has been provided.
public override string FormatErrorMessage(string name)
if (ErrorMessage == null && ErrorMessageResourceName == null)
ErrorMessage = ValidatorResources.CreditCardAttribute_Invalid; //default error
notworking wrote Sep 2, 2012 at 9:41 AM
[EmailAddress(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "email_not_valid", ErrorMessage = null)]
can help until issue not resolved
RonaldEvers wrote Oct 19, 2012 at 4:43 PM
Sorry, your suggested solution ('notworking wrote Sep 2 at 6:41 PM') doesn't work at my side.
danroth27 wrote Thu at 10:12 AM
Still repros on MVC 5