问题描述
在我的模型验证中似乎获得了不一致的回报。发生的主要问题是,只要日期无效/格式错误,它将在除日期验证之外的所有其他验证上停止。
第一个请求如何不返回有关缺少的ParticipantUserId参数的错误,而第二个请求却有可能呢? 这是预期的行为吗?
在调试的同时,我注意到在失误数组中没有显示缺失的参数,而从逻辑上讲应该是?
示例:
给出以下模型:
[Required]
[Range(1,int.MaxValue,ErrorMessage = "ParticipantUserId cannot be a negative number.")]
public int? ParticipantUserId { get; set; }
public DateTime? DateEnd { get; set; }
public DateTime? DateStart { get; set; }
[MaxLength(50)]
public string ExternalReferenceKey { get; set; }
[Required]
public int? ScheduleId{get;set;}
请求1(缺少必需的ParticipantUserId并具有无效的日期):
{
"scheduleId": 1,"correspondenceNote": "DND","dateStart": "2020-016T00:00:00","dateEnd": "2020-07-16T00:00:00","ExternalReferenceKey": null,"internalNoTe": "Note","transferEnrollmentId": null
}
返回:
{
"fields": [
{
"propertyName": "dateStart","errorMessage": "Could not convert string to DateTime: 2020-016T00:00:00"
}
],"errorMessage": "One or more validation errors occurred.","statusCode": 400
}
而
请求2(缺少必需的ParticipantUserId,但具有有效的日期):
{
"scheduleId": 1,"dateStart": "2020-07-16T00:00:00","transferEnrollmentId": null
}
返回:
{
"fields": [
{
"propertyName": "ParticipantUserId","errorMessage": "The field ParticipantUserId must be between 1 and 2147483647"
}
],"statusCode": 400
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)