We've MVC-2 application with Fluent Validation (Visual Studio 2010). Recently we migrated it to Visual Studio 2013, MVC 5. After upgrading the Fluent Validation with NuGet, I get the compilation error for following members.
我们使用Fluent验证的MVC-2应用程序(Visual Studio 2010)。最近我们将它迁移到Visual Studio 2013,MVC 5.使用NuGet升级Fluent验证后,我收到了以下成员的编译错误。
Can't find namespace FluentValidation.Mvc.MetadataExtensions
找不到命名空间FluentValidation.Mvc.MetadataExtensions
I'm using UIHint, DataType, DisplayName
members from FluentValidation.Mvc.MetadataExtensions.MetadataExtensions
class. Which class should I use to fix errors?
我正在使用来自FluentValidation.Mvc.MetadataExtensions.MetadataExtensions类的UIHint,DataType,DisplayName成员。我应该使用哪个类来修复错误?
EDIT
Broken code
[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");
}
}
1 个解决方案
#1
0
It appears that these extension methods are deprecated. I created a web project to do some research.
看来这些扩展方法已被弃用。我创建了一个Web项目来做一些研究。
In any recent versions (FluentValidation.Mvc3+), I cannot find the extension methods.
在任何最新版本(FluentValidation.Mvc3 +)中,我找不到扩展方法。
When I created a project with FluentValildation.Mvc2, they exist.
当我使用FluentValildation.Mvc2创建项目时,它们存在。
You will need to either use the older library (and I don't know how well they play with the newer versions of MVC) or use the corresponding data annotations for each of the deprecated extension methods.
您将需要使用较旧的库(我不知道它们与较新版本的MVC的搭配程度如何),或者对每个不推荐使用的扩展方法使用相应的数据注释。
public class BusinessBase<T>
{
[UIHint("First Name")]
public string FirstName { get; set; }
public DateTime Dob { get; set; }
}
I hope this helps.
我希望这有帮助。
#1
0
It appears that these extension methods are deprecated. I created a web project to do some research.
看来这些扩展方法已被弃用。我创建了一个Web项目来做一些研究。
In any recent versions (FluentValidation.Mvc3+), I cannot find the extension methods.
在任何最新版本(FluentValidation.Mvc3 +)中,我找不到扩展方法。
When I created a project with FluentValildation.Mvc2, they exist.
当我使用FluentValildation.Mvc2创建项目时,它们存在。
You will need to either use the older library (and I don't know how well they play with the newer versions of MVC) or use the corresponding data annotations for each of the deprecated extension methods.
您将需要使用较旧的库(我不知道它们与较新版本的MVC的搭配程度如何),或者对每个不推荐使用的扩展方法使用相应的数据注释。
public class BusinessBase<T>
{
[UIHint("First Name")]
public string FirstName { get; set; }
public DateTime Dob { get; set; }
}
I hope this helps.
我希望这有帮助。