I have a question regarding property validation, however, I haven't yet been able to find an appropriate answer.
I have the following classes
public class IndexViewModel
{
public Film Film { get; set; }
public ReviewModel Review { get; set; }
}
public class ReviewModel
{
[RequiredIf // only fire if 'Genre' is equal to Genre.Horror]
public string Text { get; set; }
}
public class Film
{
public string Title { get; set; }
public Director Director { get; set; }
public Genre Genre { get; set; }
}
public class Director
{
public string Name { get; set; }
}
public enum Genre
{
Horror,
Thriller,
SciFi,
Drama
}
Is it possible to add a [RequiredIf]
attribute on the Text
property in ReviewModel
which fires validation based on the value of Genre
in the Film
model. Any Help would be greatly appreciated.