Чтобы выполнить сравнение без учета регистра, вы можете создать свой собственный валидатор сравнения. Вы закончите с этим.
public string Courriel { get; set; }
[EqualToIgnoreCase("Courriel", ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "E00007")]
public string CourrielConfirmation { get; set;}
Это атрибут валидации:
/// <summary>
/// The equal to ignore case.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class EqualToIgnoreCase : ValidationAttribute, IClientValidatable
{
#region Constructors and Destructors
public EqualToIgnoreCase(string otherProperty)
{
if (otherProperty == null)
{
throw new ArgumentNullException("otherProperty");
}
this.OtherProperty = otherProperty;
}
#endregion
#region Public Properties
public string OtherProperty { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; private set; }
#endregion
#region Public Methods and Operators
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
ModelClientValidationRule compareRule = new ModelClientValidationRule();
compareRule.ErrorMessage = this.ErrorMessageString;
compareRule.ValidationType = "equaltoignorecase";
compareRule.ValidationParameters.Add("otherpropertyname", this.OtherProperty);
yield return compareRule;
}
#endregion
#region Methods
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
PropertyInfo basePropertyInfo = validationContext.ObjectType.GetProperty(this.OtherProperty);
IComparable valOther = (IComparable)basePropertyInfo.GetValue(validationContext.ObjectInstance, null);
IComparable valThis = (IComparable)value;
if (valOther.ToString().ToLower() == valThis.ToString().ToLower())
{
return ValidationResult.Success;
}
else
{
return new ValidationResult("Error");
}
}
#endregion
}
На стороне клиента вы должны будете добавить эту простую регистрацию:
var isEqualToIgnoreCase = function (value, element, param) {
return this.optional(element) ||
(value.toLowerCase() == $(param).val().toLowerCase());
};
$.validator.addMethod("equaltoignorecase", isEqualToIgnoreCase);
$.validator.unobtrusive.adapters.add("equaltoignorecase", ["otherpropertyname"], function (options) {
options.rules["equaltoignorecase"] = "#" + options.params.otherpropertyname;
options.messages["equaltoignorecase"] = options.message;
});