liveBook · Manning

FromQuery attribute

As explained in Building Web APIs with ASP.NET Core

The FromQuery attribute directs ASP.NET Core model binding to obtain a parameter's value from the request query string.

The [FromQuery] attribute tells ASP.NET Core model binding to obtain a parameter’s values from the request query string. It is especially useful when a complex request DTO replaces several simple action parameters, because complex types otherwise bind from the request body by default. section 6.1.5

Bind BoardGamesController filters from the query string

Define a RequestDTO containing pagination, sorting, and filtering properties, then declare the action parameter as [FromQuery] RequestDTO input. The action reads input.FilterQuery, input.SortColumn, input.SortOrder, input.PageIndex, and input.PageSize while preserving GET query-string behavior. section 6.1.5

Attribute-based binding can select other request sources:

  • [FromRoute] uses route data; [FromForm] uses posted form fields; [FromBody] uses the request body; [FromHeader] uses HTTP headers; and [FromServices] uses a registered service. section 6.1.5
  • Use [FromQuery] explicitly when a complex DTO must retain query-string binding rather than use the default request-body binding. section 6.1.5

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains explicit complex-parameter binding, alternatives, and DTO property usage, but does not detail binder internals.
Examples
Uses BoardGamesController.Get with RequestDTO input and demonstrates filtering, sorting, pagination, and response construction.
What it assumes
Assumes familiarity with controller actions and complex DTO parameters while showing why body binding must be overridden.
What you can do after
Apply it via ASP.NET Core to bind a request DTO’s properties from GET query parameters.
How it connects
Connects model binding with query strings, complex DTOs, validation attributes, filtering, sorting, and pagination.

Also explained in

Compare how 3 books explain FromQuery attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.