Utilizing validation in the model to enforce business rules.
In this article, I will illustrate some of the basic validation types available to ensure business rules for data are enforced.
Since MVC provides this capability within the Model, separation of concerns are maintained by keeping this logic out of the Controller and the View.
The most basic validation is the Required attribute. This ensures that field isn’t when empty.
The Range attribute ensures that a value falls within a specified range of acceptable integers.
When you need to ensure a value contains a certain number of characters, use the StringLength attribute.
When values from different fields must match each (or a value stored elsewhere), you the Compare attribute.