MVC 3 Validation

“I’m tired of making all my decisions based on what some idiot might possibly do.”
– Bill Maher

When the brilliant comedian Bill Maher made that joke 15 years ago, he wasn’t talking about software development, but life in general.  But he may as well have.  I was a Computer Science student at the time and just being introduced into the world of validation, where some idiot might possible include a number or a ‘£’ character in his or her surname.  With the advent of the web, validation seems to have become more about hacking prevention than helping customers who make genuine mistakes.

There have been many ways of doing validation over the years, including javascript and asp.net validators.  MVC 3 attempts to make validation as modular as possible, where developers can set requirements on fields once during class design, rather than write the same validation check on every form that the field of a class is edited.  There is a great, as simple as possible, step by step outline on MVC 3 validation at this dotnetkicks article.

The great thing about MVC3 validation, is separation.  Rules about what fields are required and the message that a user sees when that rule is broken is defined on the model classes.  These rules can be applied on many forms.

Advertisements
This entry was posted in Technical. Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s