Hi all,
Goal
---
I'm trying to do something pretty straightforward -- validate the basics of a login form using MVC in .NET 4.5 with FluentValidation.MVC4 (via `Install-Package FluentValidation.MVC4`).
Problem
---
When I attempt to add `[Validator(typeof(LoginViewmodelValidator))]` to my ViewModel class, as I think is indicated [in the docs](https://fluentvalidation.codeplex.com/wikipage?title=mvc), I receive an error:
> System.ComponentModel.DataAnnotations.Validator is not an attribute class.
Assuming I'm missing something (likely just a proper reference, but maybe something more).
What am I doing wrong? Thanks for any help you can give!
Code For Reference
---
In my __global.asax App_Start()__, I have:
`FluentValidationModelValidatorProvider.Configure();`
I've got my __Validator__:
````
public class LoginViewModelValidator : AbstractValidator<LoginViewModel>
{
public LoginViewModelValidator()
{
RuleFor(x => x.UserName)
.NotEmpty().WithMessage("Username must not be empty.")
.EmailAddress().WithMessage("Username must be a valid e-mail address.");
RuleFor(x => x.Password)
.NotEmpty().WithMessage("Password must not be empty.");
}
}
````
And I'm attempting the following on __my ViewModel:__
````
[Validator(typeof(LoginViewModelValidator))]
public class LoginViewModel
{
public string UserName { get; set; }
public string Password { get; set; }
public bool RememberMe { get; set; }
public string ReturnUrl { get; set; }
}
````
Goal
---
I'm trying to do something pretty straightforward -- validate the basics of a login form using MVC in .NET 4.5 with FluentValidation.MVC4 (via `Install-Package FluentValidation.MVC4`).
Problem
---
When I attempt to add `[Validator(typeof(LoginViewmodelValidator))]` to my ViewModel class, as I think is indicated [in the docs](https://fluentvalidation.codeplex.com/wikipage?title=mvc), I receive an error:
> System.ComponentModel.DataAnnotations.Validator is not an attribute class.
Assuming I'm missing something (likely just a proper reference, but maybe something more).
What am I doing wrong? Thanks for any help you can give!
Code For Reference
---
In my __global.asax App_Start()__, I have:
`FluentValidationModelValidatorProvider.Configure();`
I've got my __Validator__:
````
public class LoginViewModelValidator : AbstractValidator<LoginViewModel>
{
public LoginViewModelValidator()
{
RuleFor(x => x.UserName)
.NotEmpty().WithMessage("Username must not be empty.")
.EmailAddress().WithMessage("Username must be a valid e-mail address.");
RuleFor(x => x.Password)
.NotEmpty().WithMessage("Password must not be empty.");
}
}
````
And I'm attempting the following on __my ViewModel:__
````
[Validator(typeof(LoginViewModelValidator))]
public class LoginViewModel
{
public string UserName { get; set; }
public string Password { get; set; }
public bool RememberMe { get; set; }
public string ReturnUrl { get; set; }
}
````