5.4. Summary

In this chapter, we have discussed client and server validation. Validation is a very common problem and will pretty much be needed in every project you work on. If you can only implement one type of validation, then it should be on the server. Client-side validation alone is not secure enough because, as previously mentioned, it is not secure and can be circumvented.

We discussed how to simplify validation by simply adding attributes to the model. In my opinion, this is a very clean and loosely coupled solution to the validation problem. Using the attributes defined on the model, we can then have a validation framework that reads these attributes and validates the model accordingly.

We also used the attribute to generate the appropriate JavaScript to perform client validation. Again, this is very clean and repeatable throughout the project and even throughout other projects. We will not have to write JavaScript code for every form and every field; we simply generate the scripts based on the model attributes.

Get ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.