我正在使用 Griffin.MvcContrib 进行元数据消息错误验证。
我添加了自定义验证以添加正则表达式验证:
protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes) {
List<ModelValidator> vals = base.GetValidators(metadata, context, attributes).ToList();
//if (metadata.ModelType.Name == "DateTime")
if (metadata.DataTypeName == "telephone") {
DataAnnotationsModelValidationFactory factory;
RegularExpressionAttribute regex = new RegularExpressionAttribute(@"^(((\+?34([ |\-])?)|(\+?\(34\)([ |\-])?))?[9|6|7]((\d{1}([ |\-])?[0-9]{3})|(\d{2}([ |\-])?[0-9]{2}))([ |\-])?[0-9]{2}([ |\-])?[0-9]{2})$");
//regex.ErrorMessage = "Invalid date format";
if (!AttributeFactories.TryGetValue(regex.GetType(), out factory))
factory = DefaultAttributeFactory;
vals.Add(factory(metadata, context, regex));
}
return vals.AsEnumerable();
}
在全球阿萨克斯:
ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(myResouceFile);
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new MovilityMetadataValidatorProvider());
在资源中我有下一个键
CommonPrompts_RegularExpression {0} fu
Phone_RegularExpression {0} fa
RegularExpression Incorrect Format
但它一直向我显示这条消息:
El campo [es-ES: Phone] debe coincidir con la expresión regular '^(((+?34([ |-])?)|(+?(34)([ |-])?))?[9 |6|7]((\d{1}([ |-])?[0-9]{3})|(\d{2}([ |-])?[0-9]{2} ))([ |-])?[0-9]{2}([ |-])?[0-9]{2})$'。
我还添加了消息:
AgentDto_Phone_RegularExpression {0} regular
AgentCreateEditViewModel_AgentDto_Phone_RegularExpression {0} regular
没有任何运气。
我要在资源中添加什么来更改消息?