I am attempting to use FluentValidation 2.0 with an MVC 3 project. I have followed the instructions here to install FV within the project.
This is my validator class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentValidation;
namespace HandicapTracker.Models.Validation
{
public class TournamentValidator : AbstractValidator<Tournament>
{
public TournamentValidator()
{
RuleFor(x => x.CourseId).NotEmpty();
RuleFor(x => x.TournamentDate).NotEmpty().NotEqual(new DateTime());
}
}
}
Here is where I attempt to use the attribute:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using HandicapTracker.Configuration;
using HandicapTracker.Models.Validation;
using Omu.ValueInjecter;
using FluentValidation;
using HandicapTracker.Models.Validation;
namespace HandicapTracker.Models
{
[Validator(typeof(TournamentValidator))]
public class Tournament : HandicapTrackerModelBase
{
private const int VisitingTeamIndex = 0;
private const int HomeTeamIndex = 1;
public Tournament() : this (new League())
{
}
....
}
However, the attribute is not being recognized. When I build I get the following error message:
"System.ComponentModel.DataAnnotations.Validator" is not an attribute class.
I have actually tried this on two different solutions and am having the same problem on both. It's probably something trivial, but I can't figure it out.
Can someone tell me what i am doing wrong?
Thanks.