如何使用FluentValidation.AspNetCore和FluentValidation.MVC6来验证AspNetCore中的实体,有谁可以举个例子?
@H_403_2@
解决方法
这对我有用:
project.json添加:
"FluentValidation.AspNetCore": "6.4.0-beta3"
startup.cs
services .AddMvc() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<Startup>());
验证:
public class Foo { public string Bar {get; set;} } public class FooValidator : AbstractValidator<Foo> { public FooValidator() { RuleFor(x => x.Bar).NotEmpty().WithMessage("Error Message"); } }@H_403_2@ @H_403_2@ 原文链接:https://www.f2er.com/aspnet/245788.html