At the bottom of this question is a model containing three properties: OldPassword, NewPassword and ConfirmPassword. These display in a Change Password form. I've localized all of the error messages, except one: I cannot fully localize the error message when the Compare attribute fails. As you'll see, I'm reading the error message from a string named FieldMismatch in my resource file. Here's that string in the Spanish resource file:
El campo {0} y {1} campo no coinciden.
The {0} part is correctly getting replaced with the translation for OldPassword, but i don't know how to localize the pointer to NewPassword.
So to recap, I'm looking a way to replace [Compare("NewPassword", ... with [Compare(Resources.Culture.Account.Account.NewPassword, ...
Anyone have any thoughts on the best way to accomplish this?
public class LocalPasswordModel
{
[Required(ErrorMessageResourceName = "FieldIsRequired", ErrorMessageResourceType = typeof(Resources.Culture.Home.Global))]
[DataType(DataType.Password)]
[Display(Name = "CurrentPasswordLabel", ResourceType = typeof(Resources.Culture.Account.Account))]
public string OldPassword { get; set; }
[Required(ErrorMessageResourceName = "FieldIsRequired", ErrorMessageResourceType = typeof(Resources.Culture.Home.Global))]
[StringLength(100, ErrorMessageResourceName = "NewPasswordLength", ErrorMessageResourceType = typeof(Resources.Culture.Account.Account), MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "NewPasswordLabel", ResourceType = typeof(Resources.Culture.Account.Account))]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "ConfirmPasswordLabel", ResourceType = typeof(Resources.Culture.Account.Account))]
[Compare("NewPassword", ErrorMessageResourceName = "FieldMismatch", ErrorMessageResourceType = typeof(Resources.Culture.Home.Global))]
public string ConfirmPassword { get; set; }
}