...

/

Binders

Binders

In this lesson, we will learn how to use Binders for form filling.

During the action methods, parameters-filling stage data extracted from headers, routes, query strings, and form fields is not processed by a single software module but by several objects called binders. Each binder is specialized for a particular .NET type, or for a whole category of C# types. More specifically, there are:

  • Model binders that are specific for each .NET basic type (string, Guid, int, long, decimal, float).

  • A binder that handles all complex types, that is, a binder for the types with several properties.

  • A binder specific for any IEnumerable.

  • A binder that handles all Dictionary<S, T>.

The model binding process is recursive and starts from the type of the parameter. If the type is a simple type, the binder immediately fills the parameter. Otherwise it recursively invokes the binders for all parts that compose the type, that might be properties, all elements of a collection, all keys, and all values of a dictionary.

Whenever recursion goes down, a suffix is added to the name of the lookup source. For example, the Address property of a Person type would add an “Address” suffix to current lookup name. Similarly, the .Town suffix is added to the Town property of the address, which leads to a total prefix of Address.Town.

Two initial prefixes are tried, the ...

Access this course and 1400+ top-rated courses and projects.