I did MVC 2 two years ago. I am now using MVC 4 and would like to confirm a few things (StackOverflow is down for maintenance just now for about an hour).
In MVC 4, we do not need to create a ModelMetadata class to annotate with data annotations for data validation. We may simply annotate the model classes themselves.
In other words, if we are using the EDM generator to generate a model and corresponding classes for us, then we may create a new set of partial classes with the same names and use data annotation attributes on those partial classes themselves.
For data annotations to work, we need a reference only to System.ComponentModel.DataAnnotations and not to Microsoft.Web.Mvc.DataAnnotations.
We do not need to instantiate the default model binder in the Application_Start event in the Global.asax file.
Could you please confirm if my understanding is correct?
All of those affirmations are correct. The MVC codebase has changed a lot since version 2. All of the model validation is made by using attributes from the System.ComponentModel.DataAnnotations namespace.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.