ImmortalStrawberry
ImmortalStrawberry

Reputation: 6091

Valid values for ModelClientValidationRule ValidationType string?

Is there a lsit of what validation rule types are directly available, without having to code a new one?

e.g.

JQuery.validation has "min(value)"

But I have tried

var rule = new ModelClientValidationRule();
rule.ErrorMessage = ErrorMessage;
rule.ValidationParameters.Add("required", true);
rule.ValidationParameters.Add("min", _minDate);
rule.ValidationType = "min";
yield return rule;

without success.

Are the only options the inherited classes?

Upvotes: 4

Views: 3922

Answers (2)

V-SHY
V-SHY

Reputation: 4125

Refer to Remote Client Side Validation with FluentValidation, you can make use of the existing remote validator by doing

            var rule = new ModelClientValidationRule
            {
                ValidationType = "remote",
                ErrorMessage = message
            };
            rule.ValidationParameters.Add("url", "/api/validation/uniqueemail");

            yield return rule;

I think you can change the type you want to use by specify the ValidationType.

You can get the List of built-in Validation methods. Refer to that table, it includes the required and min you need.

Upvotes: 0

dove
dove

Reputation: 20674

Taken from jquery documentation, I would suspect you cannot use date type but convert your date to a number and it will probably work.

enter image description here

Upvotes: 5

Related Questions