protected virtual void NormalizeValidationAttrbute(ValidationAttribute validationAttribute) { if (validationAttribute.ErrorMessage == null) { ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute); } }
public override ValidationResult GetOrDefault(ValidationAttribute validationAttribute, object validatingObject, ValidationContext validationContext) { var resourceSource = _abpMvcDataAnnotationsLocalizationOptions.AssemblyResources.GetOrDefault(validationContext.ObjectType.Assembly); if (resourceSource == null) { return(base.GetOrDefault(validationAttribute, validatingObject, validationContext)); } if (validationAttribute.ErrorMessage == null) { ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute); } if (validationAttribute.ErrorMessage != null) { validationAttribute.ErrorMessage = _stringLocalizerFactory.Create(resourceSource)[validationAttribute.ErrorMessage]; } return(base.GetOrDefault(validationAttribute, validatingObject, validationContext)); }
protected virtual void AddExtraPropertyValidationsAttributes(ViewContext viewContext, ModelExplorer modelExplorer, IDictionary <string, string> attributes) { var nameAttribute = attributes.GetOrDefault("name"); if (nameAttribute == null) { return; } var extraPropertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(nameAttribute); if (extraPropertyName == null) { return; } //TODO: containerName can be null on controller actions..? var containerName = ExtraPropertyBindingHelper.ExtractContainerName(nameAttribute); if (containerName == null) { return; } if (modelExplorer.Container?.ModelType == null) { return; } var extensibleObjectType = modelExplorer.Container.ModelType .GetProperty(containerName, BindingFlags.Instance | BindingFlags.Public) ?.PropertyType; if (extensibleObjectType == null) { return; } var extensionPropertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull( extensibleObjectType, extraPropertyName ); if (extensionPropertyInfo == null) { return; } if (modelExplorer.Metadata is DefaultModelMetadata metadata) { metadata.DisplayMetadata.DisplayName = () => extensionPropertyInfo.GetLocalizedDisplayName(_stringLocalizerFactory); } foreach (var validationAttribute in extensionPropertyInfo.GetValidationAttributes()) { var validationContext = new ClientModelValidationContext( viewContext, modelExplorer.Metadata, _metadataProvider, attributes ); if (validationAttribute.ErrorMessage == null) { ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute); } var validationAttributeAdapter = _validationAttributeAdapterProvider.GetAttributeAdapter( validationAttribute, _validationStringLocalizer ); validationAttributeAdapter?.AddValidation(validationContext); } }