I'm trying out Fluent Validation using the Contoso University project.
So I've added a validator attribute to an existing class:
[Validator(typeof(PersonValidator))]
public abstract class Person
{
public int ID { get; set; }
[Required]
[StringLength(50)]
[Display(Name = "Last Name")]
public string LastName { get; set; }
}
My PersonValidator
doesn't do anything yet:
public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
}
}
But when I access the create page for a Student my debugger stops on the EditorFor
line....
@Html.EditorFor(model => model.LastName,
new { htmlAttributes = new { @class = "form-control" } })
….and I get an error:
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required
I don't appear to have the same validation on the same element more than once, so why am I getting the error? Can Fluent Validation work alongside MVC's built in validation?