Model Binding
Model binding is the process of mapping the model data coming from the view to the ViewModel parameter of the action method in the controller.
Model binding eliminates the need to read the form data manually and assign it to the existing object. This would have been very tedious and error-prone. Model binding can also be enhanced and customized. It is a powerful mechanism to parse the incoming request automatically.
Let us consider a simple form with a couple of form fields: Name
and EmailID
. On submission of the form, these values would be mapped to the ViewModel object of the action method of the controller. Model binding takes care of this mapping. The model binder looks for a match in the form fields, query strings, and request parameters.
In the preceding example, any class with these properties would be picked up by ModelBinder without any issues.
As the following Person
class contains the Name
and EmailID
properties, the model binder would not complain about using this model...