私は彼らが過去に尋ねたことを見てきましたが、間接的な方法でのみ質問に対する答えはありませんでした.
問題は、親から子を介してパラメータを取得できないことです
public class ParentModel
{
public int statusBakashaID { get; set; }
public ChildModel Children { get; set; }
//.....
//.....
}
public class ChildModel
{
[myRequired(ErrorMessage = "",OtherProperty ="statusBakashaID")]
public string id { get; set; }
//.....
//.....
}
public class myRequired: ValidationAttribute
{
public string OtherProperty { get; set; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var otherProperty = validationContext.ObjectType.GetProperty(OtherProperty);
var otherPropertyValue =
(int)otherProperty.GetValue(validationContext.ObjectInstance,null);
if(otherPropertyValue == 1){
//.....
}
return null
}
}