28 Using model binding

 

This chapter covers

  • Understanding how the ASP.NET Core model binder reads data values from HTTP requests
  • Finding data values during model binding
  • Customizing the model binding process and performing model binding manually

Model binding is the process of creating .NET objects using the values from the HTTP request to provide easy access to the data required by action methods and Razor Pages. In this chapter, I describe the way the model binding system works; show how it binds simple types, complex types, and collections; and demonstrate how you can take control of the process to specify which part of the request provides the data values your application requires. Table 28.1 puts model binding in context.

28.1 Preparing for this chapter

28.1.1 Dropping the database

28.1.2 Running the example application

28.2 Understanding model binding

28.3 Binding simple data types

28.3.1 Binding simple data types in Razor Pages

28.3.2 Understanding default binding values

28.4 Binding complex types

28.4.1 Binding to a property

28.4.2 Binding nested complex types

28.4.3 Selectively binding properties

28.5 Binding to arrays and collections

28.5.1 Binding to arrays

28.5.2 Binding to simple collections

28.5.3 Binding to dictionaries

28.5.4 Binding to collections of complex types

28.6 Specifying a model binding source

28.6.1 Selecting a binding source for a property

28.6.2 Using headers for model binding

28.6.3 Using request bodies as binding sources

28.7 Manual model binding

Summary