尝试在我的api中验证对象,该对象包含另一个对象的列表,我需要验证列表计数必须大于0,并且列表内的属性具有另一个数据注释也需要验证
``
public class CmsRequestBody
{
[JsonProperty("n")]
public int n { get; set; }
[JsonProperty("locale")]
[Required]
public string Locale { get; set; }
[JsonProperty("questionList")]
[Required]
[EnsureOneElement(ErrorMessage = "At least a person is required")]
[ValidateEachItemAttribute]
public List<Question> QuestionList;
}
public class Question
{
[Required]
[TwelveDigit]
[JsonProperty("objectId")]
public long ObjectId { get; set; }
[Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
[Required]
[JsonProperty("instanceNumber")]
public int InstanceNumber { get; set; }
}``
当我在数据注释自定义代码中添加断点而不输入代码时,这是对象和我的自定义数据注释属性
答案 0 :(得分:0)
我想添加的答案
{ get; set; }
for property
public List<Question> QuestionList