MVC View Model Validation Logic Location

I have a data model that includes the following two properties:

 [Required] [Range(1, 12, ErrorMessage = "Value for First Month must be between {1} and {2}.")] public Int32 FirstMonth { get; set; } [Required] [Range(1, 12, ErrorMessage = "Value for Last Month must be between {1} and {2}.")] public Int32 LastMonth { get; set; } 

In addition to making sure they are between 1 and 12 I also want validation to prevent the last month from having a value less than the first month.

My question is, in the MVC framework where I'm using data annotations, where do I place this logic? Is it also in the model class and if so do I still use the data annotations for the value or also incorporate that into the code logic?

Thanks,

by nufsven via /r/csharp

Leave a Reply