从Netcore 2.2 Web API的响应中获取ErrorMessage [英] Get ErrorMessage from Response in Netcore 2.2 Web API
本文介绍了从Netcore 2.2 Web API的响应中获取ErrorMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用空的用户名和密码调用Register方法.所以我收到了这个结果:
I call Register method with empty username and password. So I received this result:
{
"errors": {
"Password": [
"The Password field is required.",
"Password length is between 4 and 8."
],
"Username": [
"The Username field is required."
]
},
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "0HLJIO56EGJEV:00000001"
}
我的Dto:
public class UserForRegisterDto
{
[Required]
public string Username { get; set; }
[Required]
[StringLength(8, MinimumLength = 4, ErrorMessage = "Password length is between 4 and 8.")]
public string Password { get; set; }
}
我只想从响应中获取错误属性,该怎么办?
I only want to get errors attribute from response, What should I do?
推荐答案
查看全文