I'm having problems with my localized Model attributes as we decided to not use the build-in localization functionallity.
public class LocalizedRequiredAttribute : RequiredAttribute
{
public LocalizedRequiredAttribute(string displayName)
{
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(LocalizedRequiredAttribute), typeof(RequiredAttributeAdapter));
ErrorMessage = ResourceProvider.Get(string.Format("resValidation{0}Missing", displayName));
}
}
The problem is that the global culture can be changed by the user but ErrorMessage, DisplayName and stuff is kind of cached by the framework. Any suggestions how to fix this and bind the attributes on runtime?
I finally found a solution for this. You just have to override the FormatErrorMessage Method: