首页
视频
资源
登录
风清月
愿你出走半生,归来仍是少年
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
mvc
9篇
c#面试题
1篇
爬虫
1篇
Redis
1篇
NET
37篇
JS相关
2篇
Oracle
1篇
随笔
30篇
学点小英语
9篇
Vue.js
3篇
jquery
2篇
Sqlerver
7篇
前端
53篇
ps
1篇
net core
39篇
更多
架构
9篇
rpc
1篇
EF
6篇
mui
8篇
微服务
8篇
微信
1篇
.net
5篇
svn
1篇
人工智能
6篇
nginx
4篇
docker
14篇
git
4篇
c++
3篇
linux
11篇
uniapp
7篇
k8s
23篇
python
3篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术
转
abp vnext验证
4191
人阅读
2022/7/11 9:25
总访问:
1638865
评论:
0
收藏:
0
手机
分类:
net core
### 验证DTO 微软官方文档:https://docs.microsoft.com/zh-cn/aspnet/core/mvc/models/validation?view=aspnetcore-7.0 **数据注解 Attribute** 使用数据注解是一种以声明式对DTO进行验证的简单方法. 示例 : ``` public class CreateBookDto { [Required] [StringLength(100)] public string Name { get; set; } [Required] [StringLength(1000)] public string Description { get; set; } [Range(0, 999.99)] public decimal Price { get; set; } } ``` 当使用该类作为应用服务或控制器的参数时,将对其自动验证并抛出本地化异常(由ABP框架处理). **IValidatableObject** IValidatableObject can be implemented by a DTO to perform custom validation logic. CreateBookDto in the following example implements this interface and checks if the Name is equals to the Description and returns a validation error in this case. 可以将DTO实现 IValidatableObject 接口进行自定义验证逻辑. 下面的示例中 CreateBookDto 实现了这个接口,并检查 Name 是否等于 Description 并返回一个验证错误. ``` using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Acme.BookStore { public class CreateBookDto : IValidatableObject { [Required] [StringLength(100)] public string Name { get; set; } [Required] [StringLength(1000)] public string Description { get; set; } [Range(0, 999.99)] public decimal Price { get; set; } public IEnumerable<ValidationResult> Validate( ValidationContext validationContext) { if (Name == Description) { yield return new ValidationResult( "Name and Description can not be the same!", new[] { "Name", "Description" } ); } } } } ``` 原文:https://docs.abp.io/zh-Hans/abp/latest/Validation
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}