I've an issue with validating user input in bootstrap modal before form submission. I have a class with this property
[FooValidation]
[MaxLength(50)]
[Required]
public string Foo {get;set;}
the foo property has to be unique so that's why I created FooValidation attribute which looks like this:
public class FooValidationAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
//logic
return true;
}
}
And in my view I have
@Html.TextBoxFor(model => model.Foo, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Foo)
Now the problem is, default attributes (Required and MaxLength) work just fine, when I try to submit the form I get the proper error messages, but my custom attribute doesn't, the IsValid method is called and returns proper value but the form gets submitted no matter what. Any idea what might be wrong?
PS: I tried to override this method
ValidationResult IsValid(object value, ValidationContext validationContext)
as well but the result is the same.