是否可以在同一个FluentValidation中同时运行和 IValidatableObject?例如,如果我有以下ViewModel:
public class TestViewModel
{
public Foo Foo { get; set; }
public Bar Bar { get; set; }
}
public class Foo : IValidatableObject
{
public string FooName { get; set; }
public IEnumerable<ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext)
{
if (string.IsNullOrEmpty(FooName))
{
yield return new ValidationResult("Required from IValidatableObject", new[] { "FooName" });
}
}
}
[Validator(typeof(BarValidator))]
public class Bar
{
public string BarName { get; set; }
}
public class BarValidator : AbstractValidator<Bar>
{
public BarValidator() {
RuleFor(x => x.BarName).NotNull().WithMessage("Required from FluentValidation");
}
}当我的控制器调用Foo和Bar时,是否有一种方法可以运行并返回结果
发布于 2017-08-16 12:54:07
https://stackoverflow.com/questions/45620471
复制相似问题