Valid values for ModelClientValidationRule Validat

2019-05-03 23:50发布

问题:

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?

回答1:

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



回答2:

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.