您好我正在尝试在 ASPNET MVC 4 项目上实现 IValidableObject 接口。我的模型在不同的程序集中,当框架执行我的验证方法时,它没有显示验证上下文并向我显示此错误:验证上下文无法通过嵌套类型访问外部类型“AS.Core.Model.Horario.Validate”的非静态成员'AS.Core.Model.Horario'
很明显,问题出在单独的程序集上,但我不知道该怎么做才能完成这项工作,有人可以帮助我吗?
这是我的代码:
public class Horario : IValidatableObject
{
[Range(0, 6, ErrorMessage = "Dia inválido")]
public byte Dia { get; set; }
[DataType(DataType.Time, ErrorMessage = "Horário de início inválido")]
public TimeSpan? HorarioInicio { get; set; }
[DataType(DataType.Time, ErrorMessage = "Horário fim inválido")]
public TimeSpan? HorarioFim { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (HorarioInicio != null && HorarioFim == null || HorarioFim != null && HorarioInicio == null)
{
yield return new ValidationResult("Horário inválido");
}
}
}