Tutorials ASP.NET Core MVC Mastery
FromQuery vs FromRoute
On this page
Model Binding Masterclass: Mastering Request Sources
1. [FromQuery] (The Search & Filter Source)
Typically used for pagination, filtering, and optional parameters. /Products?id=123. Values are optional.
2. [FromRoute] (The Immutable Resource Source)
Used to identify a specific record in a RESTful manner. /Products/123/Details. If the route parameter is missing, the request fails (404).
Advanced: [FromHeader] & [FromServices]
A 12-year expert knows that sometimes the best data is in a Header (e.g. api-version) or passed directly from the DI container into the action method without hitting the constructor ([FromServices]).
Architect Insight: Custom Model Binder
For cases like custom encrypted tokens or non-standard date formats, you can create an IModelBinder. This is the ultimate tool for clean, professional controllers that don't deal with parsing "Garbage Strings".