I use data annotations to validate my Web API 2 models. For basic attribute-based validation ( Required, Rangeetc.) It is fairly easy to provide localized messages by entering a custom one ModelMetadataProvider. However, for more complex rules, I implement IValidatableObjectthat returns a sequence ValidationResult:
public class ValidationResult
{
public ValidationResult(string errorMessage);
public ValidationResult(string errorMessage, IEnumerable<string> memberNames);
}
There seems to be no way to indicate here ErrorMessageResourceName. And I do not want my models to depend on the localization provider. How can i solve the problem?
source
share