カスタム検証に使用される次のクラスがあります。
[AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
public sealed class RequiredIfAnyTrueAttribute : ValidationAttribute, IClientValidatable
{
    private const string DefaultErrorMessage = "{0} is required";
    public List<string> OtherProperties { get; private set; }
    public RequiredIfAnyTrueAttribute(string otherProperties)
        : base(DefaultErrorMessage)
    {
        if (string.IsNullOrEmpty(otherProperties))
            throw new ArgumentNullException("otherProperty");
        OtherProperties = new List<string>(otherProperties.Split(new char[] { '|', ',' }));
    }
    public override string FormatErrorMessage(string name)
    {
        return string.Format(ErrorMessageString, name);
    }
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        if (value == null)
        {
            foreach (string s in OtherProperties)
            {
                var otherProperty = validationContext.ObjectType.GetProperty(s);
                var otherPropertyValue = otherProperty.GetValue(validationContext.ObjectInstance, null);
                if (otherPropertyValue.Equals(true))
                    return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
            }
        }
        return ValidationResult.Success;
    }
    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
        var clientValidationRule = new ModelClientValidationRule()
        {
            ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
            ValidationType = "requiredifanytrue"
        };
        clientValidationRule.ValidationParameters.Add("otherproperties", string.Join("|",OtherProperties));
        return new[] { clientValidationRule };
    }
}
私のViewModelは次のとおりです。
public class SampleViewModel
{
    public bool PropABC { get; set; }
    public bool PropXYZ { get; set; }
    [RequiredIfAnyTrue("PropABC|PropXYZ")]
    public int? TestField { get; set; }
}
強く型付けされたビューがレンダリングされると、すべて正常に動作するように見えます。PropABC または PropXYZ が選択されている場合は、TestField の値を入力する必要があります。クライアント側とサーバー側の両方の検証が機能します。
ただし、次の一連のイベントがあるとします。
- PropABCをチェック
 - フォームを送信
 - TestField のクライアント側検証が必要です
 - PropABCのチェックを外す
 - クライアントの検証が再起動せず、フォームが送信されるまで検証メッセージが残る
 
#5 を解決するために、私は通常、jquery onready を介してクリック イベントをチェックボックスにアタッチし、検証を再起動します。
MVC3 + 目立たない + jquery を指定して、クライアント側の検証を手動で強制する推奨/推奨方法はありますか?