首页 > Web开发 > 详细

ASP NET Core ---FluentValidation

时间:2018-09-04 22:54:58      阅读:211      评论:0      收藏:0      [点我收藏+]

官方文档:https://fluentvalidation.net/

 

一、安装:

技术分享图片

 

 二、应用:

         1、建立PostValidator:

   public class PostValidator:AbstractValidator<PostDTO>
    {
        public PostValidator()
        {
            RuleFor(x => x.Author).NotEmpty()
                .WithName("作者").WithMessage("{PropertyName}是必须填写的")
                .MaximumLength(50).WithMessage("{PropertyName}的最大长度是{MaxLength}");
        }
    }

          2、aspnetcore注册:

services.AddTransient<IValidator<PostDTO>, PostValidator>();

 

 

参考资料:https://v.qq.com/x/page/z0763a2x3j5.html

 

ASP NET Core ---FluentValidation

原文:https://www.cnblogs.com/fuyouchen/p/9588987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!