Custom validation attribute error message

Vote:
 

Hi all,

We have a custom validation attribute. Within the attribute we have overridden the FormatErrorMEssage method, like so:

public override string FormatErrorMessage(string name)
        {
            return String.Format(CultureInfo.CurrentCulture, ErrorMessage, name, _types.Select(s => s.Name));
        }

On our model, if we add the attribute to a property like so:

[OurValidationAttribute(new [] { typeof(AllowedType1) }, ErrorMessage = "The property '{0}' can only have types of '{1}')]
public virtual LinkItemCollection Links {get;set;}

The validation error message returned is 'The property 'Links' can only have types of 'AllowedType1'.

However, if we want to use a localized string, i.e.:

[OurValidationAttribute(new [] { typeof(AllowedType1) }, ErrorMessage = "/errormessages/linkitemcollection')]
public virtual LinkItemCollection Links {get;set;}

The message returned is "The property '{0}' can only have types of '{1}'"

i.e. the Localization has not occured.

Has anyone else seen this? Any thoughts on how to get round this?

Thanks in advance

Al

#113557
Nov 24, 2014 16:31
Vote:
 

"i.e. the Localization has not occured." Sorry, what I should have said, is the Localization has taken place, but the formatting of the args has not....

#113559
Nov 24, 2014 17:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.