问题回现:
public class ShipmentRequestDto
{
public string FromPhoneNumber { get; set; }
/// <summary>
/// 发货人行政区域编码
/// </summary>
[Required(AllowEmptyStrings = false, ErrorMessage = "发货地未选择")]
public string FromAreaCode { get; set; }
/// <summary>
/// 保价
/// </summary>
public decimal ProtectPrice { get; set; }
}
上面代码中FromAreaCode 应用了标注验证,还有一个可填可不填的ProtectPrice 字段,客户端如果把ProtectPrice字段传成字符型的话,api返回的验证信息中则会丢失掉所有ErrorMessage中的信息,例如“发货地未选择”
{
"fromAreaCode": "test", "protectPrice": '' }
上述数据请求后,api返回的信息如下:
{ "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "您的请求无效!", "details": "[Validation narrative title]\r\n - \r\n", "validationErrors": [ { "message": "", "members": [ "fromAreaCode " ] } ] }, "unAuthorizedRequest": false, "__abp": true }
error.validationErrors[i].message丢失了,并没有返回我们标注的错误信息