Chapter 12Validating User Input

What you will learn in this chapter:

  • How client-side and server-side validation of input data differs
  • Changing your model classes to help support validation
  • Using validation controls to validate input in ASP.NET Web Form pages
  • Enforcing validation in ASP.NET MVC views and controllers
  • Working with controllers that return partial views
  • Some tips for implementing validation

Code Downloads for this Chapter:

The wrox.com code downloads for this chapter are found at www.wrox.com/go/beginningaspnetforvisualstudio on the Download Code tab. The code is in the chapter 12 download and individually named according to the names throughout the chapter.

There is an old saying, “garbage in, garbage out” (GIGO). The implication is clear: When you allow bad data (garbage) into your application, you will have problems from then on out because your application will give you garbage back. The best way to ensure that your application does not have garbage data is to validate as much of the incoming information as possible to ensure that it fits some known criteria, such as ensuring that a phone number includes all digits, that an e-mail address has the correct format, or a quantity is an integer; for all sorts of user-entered pieces of information, you can, and should, define some expectations regarding how that data should appear.

Both MVC and Web Forms provide support to help you keep your application as garbage-free as possible. In this chapter, you will examine ...

Get Beginning ASP.NET for Visual Studio 2015 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.