O'Reilly logo

Professional ASP.NET MVC 5 by David Matson, K. Scott Allen, Brad Wilson, Jon Galloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6Data Annotations and Validation

—by K. Scott Allen

What's In This Chapter?

  • Using data annotations for validation
  • Creating your own validation logic
  • Using model metadata annotations

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

You can find the www.wrox.com code downloads for this chapter at http://www.wrox.com/go/proaspnetmvc5 on the Download Code tab. The code for this chapter is contained in the following file: Wrox.ProMvc5.C06.zip.

Validating user input has always been challenging for web developers. Not only do you want validation logic executing in the browser, but you also must have validation logic running on the server. The client validation logic gives users instant feedback on the information they enter into a form, and is an expected feature in today's web applications. Meanwhile, the server validation logic is in place because you should never trust information arriving from the network.

When you look at the bigger picture, however, you realize how logic is only one piece of the validation story. You also need to manage the user-friendly (and often localized) error messages associated with validation logic, place the error messages in your UI, and provide some mechanism for users to recover gracefully from validation failures.

If validation sounds like a daunting chore, you'll be happy to know the MVC framework can help you with the job. This chapter is devoted to giving you everything you need to know about the validation components of the MVC framework.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required