Hi, I am trying to implement the IValidableObject interface in an ASPNET MVC 4 project. My model is in a different assembly, when the framework executes my validation method, it does not show validationContext and shows me this error: validationContext Unable to access non-stationary member of external type "AS. Core.Model.Horario.Validate "through the nested type" AS.Core.Model.Horario "
Clearly, the problem is in the individual builds, but I have no idea what to do to make this work, can anyone 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");
}
}
}
source
share