ASP.NET MVC can build editor forms for your models based on their properties. You can customize how they work - both how they're displayed and how the the validation rules work - using data annotation attributes. They're simple markers on the properties that indicate which fields are required, what data type they are, etc. You can read more about them on MSDN. Some common data annotation attributes are listed to the right of the code.
In this experiment, you can edit (or completely replace) the model definition in the code editor on the left half of the page. Then submit the form to see the editor which ASP.NET MVC will generate based on your model.
- Some annotations to try:
- Indicates that the item can't be left blank
- Specifies a maximum length for a string field. This is handy for making sure that user input can fit in database fields.
- Specifies a minimum and maximum value for a numeric field.
- A regular expresions is a string of text that defines a pattern. If you can wrap your head around the syntax, you can do a lot with regular expressions. Read more about them here.