如何解决如何将 isValid 方法的 contextValidation 参数从父级传递给子级
我看到他们过去问过,只是间接的方式没有回答这个问题,
问题是无法从父级通过子级获取参数
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
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。