1 回答
TA贡献1828条经验 获得超3个赞
这应该会给你你正在寻找的东西。
public class Report : ValidationAttribute
{
public int Score { get; set; }
public string Comment { get; set; }
public int[] ReasonIds { get; set; }
protected override ValidationResult IsValid(
object value, ValidationContext validationContext)
{
if(Score < 4 && (string.IsNullOrEmpty(Comment) || ReasonIds.Count() < 1))
{
return new ValidationResult(GeScoreErrorMessage());
}
return ValidationResult.Success;
}
private string GeScoreErrorMessage()
{
return $"If Score < 4 Comment and Reasons must be provided";
}
}
- 1 回答
- 0 关注
- 67 浏览
添加回答
举报