0

I would like to have a bool field and and a string field in my Model and not having any validation attributes on them. But in the view I would like to have the required field validation on the Editor if the Checkbox is checked.

How do I do this please?

Thank you.

4

1 に答える 1

0

データ注釈属性を引き続き使用して、このオプションのいずれかに従うことができます。

  1. アクション内のそのフィールドのモデル状態辞書からエラーをクリアします

  2. simonによって作成された条件付き検証ライブラリを使用します。

元。

public class ValidationSample
{
    [RequiredIf("PropertyValidationDependsOn", true)]
    public string PropertyToValidate { get; set; }

    public bool PropertyValidationDependsOn { get; set; }
}
于 2012-07-10T10:08:37.363 に答える