I have a situation in which I need to extract Data Annotations information from an ASP.NET ViewModel in order to perform some more advanced validations.
Instead of writing my own type descriptor class, I wonder if I can use the native one.
Even though Data Annotations are not tied to ASP.NET MVC, if there is some ASP.NET MVC specific implementation, that wouldn’t be a problem to me.
Any ideas?
As I suspected, ASP.NET MVC did create a helper to class called ModelMetadata to extract meta information from model, considering data annotation attributes. See the example:
This reduces the need of manually reading the data-annotation attributes for the basic scenarios.