Foolproof multiple validators on the same fields

前端 未结 1 1760
礼貌的吻别
礼貌的吻别 2021-01-26 10:53

I currently use foolproof for that validation:

[RequiredIfNot(\"type\", 3, ErrorMessage = \"Please enter at least one value\")]
public int[] audites { get; set;          


        
相关标签:
1条回答
  • 2021-01-26 11:48

    The Foolproof.RequiredIfNotAttribute derives from Foolproof.ModelAwareValidationAttribute (which in turn derives from System.ComponentModel.DataAnnotation.ValidationAttribute). ModelAwareValidationAttribute is marked with [AttributeUsage(AttributeTargets.Property)]. Refer source code. By default the the AllowMultiple parameter of AttributeUsage is false which means that you can only apply the attribute once to a property. You have tried to apply it 3 times, hence the error.

    Having it true and allowing it to be applied multiple times would possibly cause problems in setting the $.validator.methods and $.validator.unobtrusive.adapters functions used by unobtrusive validation.

    You will need to use some other validation attributes or create your own ValidationAtribute that implements IClientValidatable, or rely on server side validation.

    0 讨论(0)
提交回复
热议问题