Hi I'm trying to implement IValidableObject interface on a ASPNET MVC 4 project. My model is in a different assembly, when the framework executes my validate method it shows no validationContext and shows me this error: validationContext Cannot access a non-static member of outer type 'AS.Core.Model.Horario.Validate' via nested type 'AS.Core.Model.Horario'
It's clear that the problem is about separate assemblies but I have no idea what to do to make this work, anybody could help me?
This is my code:
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");
}
}
}