MVC: Validation

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.

Required

The most basic validation is the Required attribute. This ensures that field isn’t when empty.

1-mvc-validation

Range

The Range attribute ensures that a value falls within a specified range of acceptable integers.

1-mvc-validation

2-mvc-validation

StringLength

When you need to ensure a value contains a certain number of characters, use the StringLength attribute.

3-mvc-validation

4-mvc-validation

Compare

When values from different fields must match each (or a value stored elsewhere), you the Compare attribute.

5-mvc-validation

6-mvc-validation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s