我想本地化错误用户输入的错误消息。
例如分钟。城市名称的长度为 2 个字符。
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Validation))]
[StringLength(50, ErrorMessageResourceName = "Max", ErrorMessageResourceType = typeof(Validation))]
[RegularExpression(".{2,}", ErrorMessageResourceName = "Min", ErrorMessageResourceType = typeof(Validation))]
public string City { get; set; }
错误资源字符串当前看起来像:“没有足够的字符”。
现在我想添加一个更具体的错误消息,例如“至少需要 2 个字符”。
但是如何通过使用ErrorMessageResourceName
和例如将参数传递给本地化资源字符串,例如“所需的最少 {0} 个字符” String.Format()
?
谢谢!