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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -