How does model binding work in ASP.NET MVC?

ASP.NET MVC Model Binding & Validation Basic 1–2 Yrs2–3 Yrs Conceptual 1 min read

Quick Answer

Model binding maps incoming request values (route, query string, form body, headers) onto your action's parameters by matching names. A parameter Customer c gets its properties filled from keys like Name, Email; nested and collection properties use dotted/indexed names (Address.City, Items[0].Qty).

Model binding is the framework taking the raw request — form fields, query string, route values — and populating my action parameters by matching names. If my action takes a Customer, the binder looks for Name, Email and so on in the request and fills the properties, converting the strings along the way. Nested objects and lists use dotted and indexed names. If a value can't convert, that's a model-state error, not an exception, and then validation runs on top and adds its own errors to ModelState.

  • The binder walks the target type's properties and looks each one up in the value providers, converting strings to the property type.
  • Binding failures (a non-numeric value for an int) add errors to ModelState rather than throwing.
  • After binding, validation runs and also populates ModelState.
  • Custom binders (IModelBinder) handle non-standard formats — e.g. a comma-separated id list, or building an object from a header.