我们已经使用了MVC-2应用程序进行了流畅的验证(Visual 2010)。最近我们把它迁移到Visual 2013,MVC 5。在用NuGet升级了Fluent验证之后,我得到了以下成员的编译错误。
找不到namespace FluentValidation.Mvc.MetadataExtensions
我正在使用来自UIHint, DataType, DisplayName类的FluentValidation.Mvc.MetadataExtensions.MetadataExtensions成员。我应该使用哪个类来修复错误?
编辑
破译代码
[FluentValidation.Attributes.Validator(typeof(class1Validator))]
public partial class class1: BusinessBase<decimal>
{
}
public class class1Validator: FluentValidation.AbstractValidator<class1>
{
public class1Validator()
{
RuleFor(o => o.FirstName).NotEmpty().Length(1, 60).UIHint("First Name"); //giving error for UIHint
RuleFor(o => o.Dob).DataType(System.ComponentModel.DataAnnotations.DataType.Date).GreaterThan(DateTime.MinValue).LessThan(DateTime.Now); //giving error for datatype
}
}
public class SearchValidator : FluentValidation.AbstractValidator<SearchCriteria>
{
public SearchValidator()
{
RuleFor(o => o.Id).DisplayName("User ID"); //giving error for DisplayName in both lines
RuleFor(o => o.LastName).DisplayName("Last Name");
}
}发布于 2015-10-09 19:34:23
看来,这些扩展方法是不可取的。我创建了一个网络项目来做一些研究。
在任何最新版本(FluentValidation.Mvc3+)中,我都找不到扩展方法。
当我用FluentValildation.Mvc2创建一个项目时,它们是存在的。
您需要使用旧的库(我不知道它们对新版本的MVC使用得有多好),也需要为每个不推荐的扩展方法使用相应的数据注释。
public class BusinessBase<T>
{
[UIHint("First Name")]
public string FirstName { get; set; }
public DateTime Dob { get; set; }
}我希望这能帮到你。
https://stackoverflow.com/questions/33045122
复制相似问题