c# - How does the MetadataType attribute mark a class as a validation class in MVC? -
i have ado entity generated in mvc 2 , know if want put custom validation on object can this.
[metadatatype(typeof(myentity_validation))] public partial class myentity { private sealed class myentity_validation { [required] [regularexpression("[a-za-z][0-9]{5}")] public string somefield{ get; set; } } }
but don't know why works.
how work? sort of convention?
metadata convention, yes. see http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx. can add attributes fields enforce validation, display, concurrency, sorts of common usefulness. hope helps.
Comments
Post a Comment