liveBook · Manning

Model binding source inference

As explained in ASP.NET Core in Action, 3e

Model binding source inference is the framework process of determining where an action parameter's value should be obtained from an HTTP request or application services.

Model binding source inference determines where an action parameter gets its value. With [ApiController], complex parameters are inferred from the request body, so JSON input usually needs no explicit [FromBody] attribute. section 20.4

A simpler JSON update action

A FruitController action can accept UpdateModel directly: public ActionResult Update(UpdateModel model). [ApiController] supplies the body-binding convention that would otherwise require [FromBody]. The same attribute also handles invalid model state automatically. section 20.4

The convention changes the controller’s expected behavior:

  • Without [ApiController], complex types are assumed to come from form values and JSON binding ordinarily requires [FromBody]. section 20.4
  • With [ApiController], API actions follow the body-binding convention and invalid model state can produce automatic 400 responses. section 20.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the form-versus-body convention and omitted [FromBody], but does not detail the complete inference rule set.
Examples
Uses a FruitController Update action and contrasts explicit [FromBody] binding with inferred binding.
What you can do after
Apply it via [ApiController] to accept JSON-bound complex parameters without repeating [FromBody].
How it connects
Connects model binding with [ApiController], attribute routing, model validation, automatic 400 responses, and ProblemDetails.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.