I use FluentValidation to test my models on both the client and server side. I am in the latest version:
FluentValidation.MVC5
at the time of writing which
5.5.0.0
I have the following validator simplified:
public class MyViewModelValidator : AbstractValidator<MyViewModel>
{
public MyViewModelValidator()
{
RuleFor(x => x.Email)
.EmailAddress().WithLocalizedMessage(() => MyResources.Validation_Email_NotValidAddress)
.NotEmpty()
.WithLocalizedMessage(() => MyResources.Validation_Email);
}
}
The client side seems to perform some basic verification, for example, that it will not accept anything without text on both sides of the "@" character, however it will accept something like test@test.
The problem occurs when I send this data, I have the following in the controller:
if (!ModelState.IsValid)
throw new Exception("Model validation error");
This means that the model is invalid due to the email address test@testand throws an error. Therefore, it seems that my front-side validation is weaker than my server-side validation.
, , Email() , , , , .
https://fluentvalidation.codeplex.com/wikipage?title=mvc
, , .