Chapter 13. Recipes

 

This chapter covers

  • Implementing jQuery autocomplete text box
  • Configuring automatic client-side validation
  • Using NHibernate for data access
  • Integrating the Spark view engine

By now you have seen all of the components of the ASP.NET MVC Framework. Surely you have asked yourself, How do I do ____ in ASP.NET MVC? Certainly with a new paradigm it’s natural to feel a bit lost when trying to implement functionality in your first application. This chapter is geared toward giving you concrete examples, or recipes, for achieving common functions such as automatic validation or data access. Take these examples verbatim and use them in your applications, or simply learn from them and apply the techniques in your own way. We start with client-side functionality, move through extending validation, and through a comprehensive data access recipe. We finish by replacing the built-in view engine that comes with ASP.NET MVC, and try out the Spark view engine.

13.1. jQuery autocomplete text box

It’s not uncommon for text boxes to automatically suggest items based on what we type. The results are further filtered as we type to give us the option to select an available item with the mouse or keyboard. One of the first examples of this in the wild was Google Suggest as shown in figure 13.1.

Figure 13.1. Google Suggest filters options as you type.

13.2. Automatic client-side validation