这个问题的底部是一个包含三个属性的模型:OldPassword,NewPassword和ConfirmPassword。这些以“更改密码”形式显示。我已经本地化了所有错误消息,除了以下内容:当Compare属性失败时,我无法完全本地化错误消息。如您所见,我正在从资源文件中名为FieldMismatch的字符串中读取错误消息。这是西班牙语资源文件中的字符串:
El campo {0} y {1} campo no coinciden.
{0}部分已正确地替换为OldPassword的翻译,但是我不知道如何本地化指向NewPassword的指针。
回顾一下,我正在寻找一种替代方法
[比较(“ NewPassword”,...
与
[比较(Resources.Culture.Account.Account.NewPassword,...
有人对实现此目标的最佳方法有任何想法吗?
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; }
}
最佳答案
这看起来像是MVC4和MVC5(我正在使用)中的已知错误。看来它已在5.1中修复:
http://aspnetwebstack.codeplex.com/workitem/1401