繁体   English   中英

使用ASP.NET MVC 5进行流利验证

[英]Fluent Validation with ASP.NET MVC 5

我们已经使用了Fluent验证的MVC-2应用程序(Visual Studio 2010)。 最近,我们将其迁移到Visual Studio 2013 MVC5。用NuGet升级Fluent Validation后,我收到以下成员的编译错误。

找不到namespace FluentValidation.Mvc.MetadataExtensions

我正在使用来自FluentValidation.Mvc.MetadataExtensions.MetadataExtensions类的UIHint, DataType, DisplayName成员。 我应该使用哪个类来修复错误?

编辑

密码破损

[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");           

    }


}

这些扩展方法似乎已被弃用。 我创建了一个网络项目来做一些研究。

在任何最新版本(FluentValidation.Mvc3 +)中,我都找不到扩展方法。

当我使用FluentValildation.Mvc2创建一个项目时,它们存在。

您将需要使用较旧的库(并且我不知道它们在MVC的较新版本中的表现如何)或为每个不赞成使用的扩展方法使用相应的数据注释。

public class BusinessBase<T>
{
   [UIHint("First Name")]
   public string FirstName { get; set; }
   public DateTime Dob { get; set; }
}

我希望这有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM