Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Edited Unassigned: Where is the Validator Data Annotation Located? [7165]

$
0
0
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; }
}
````

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>