In my MVC 3.0 application, I use the database first schema of entity framework.
In the views, I want to add validation for input. Should I create a new model type for the entity that I need to validate, so that I can add validation attributes on it? Those entity types are generated by entity framework.
In my MVC 3.0 application, I use the database first schema of entity framework.
Share
No, you should create a buddy class with the MetadataType attribute that refers to a class with your validation. Check out this example:
http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validation-with-the-data-annotation-validators-cs
Specifically the section labeled Using Data Annotation Validators with the Entity Framework.