FluentValidation2.0をMVC3プロジェクトで使用しようとしています。ここの指示に従って、プロジェクト内にFVをインストールしました。
これは私のバリデータークラスです:
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());
}
}
}
これが私が属性を使おうとするところです:
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())
{
}
....
}
ただし、属性は認識されていません。ビルドすると、次のエラーメッセージが表示されます。
「System.ComponentModel.DataAnnotations.Validator」は属性クラスではありません。
私は実際にこれを2つの異なる解決策で試しましたが、両方で同じ問題が発生しています。些細なことかもしれませんが、わかりません。
誰かが私が間違っていることを教えてもらえますか?
ありがとう。