Skip to content

Commit 26135f7

Browse files
Copilotwadepickett
andauthored
De-duplicate parameter binding documentation across quick reference and dedicated article (#36253)
* Initial plan * De-duplicate parameter binding documentation Co-authored-by: wadepickett <[email protected]> * Update version-specific quick references to use parameter binding summary Co-authored-by: wadepickett <[email protected]> * Add metadata and update ms.date Co-authored-by: wadepickett <[email protected]> * Apply suggestion from @wadepickett * Apply suggestion from @wadepickett * Clean up metadata in parameter-binding-summary8-10.md Removed duplicate metadata on include. * Apply suggestion from @wadepickett --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wadepickett <[email protected]> Co-authored-by: Wade Pickett <[email protected]>
1 parent 8306c6d commit 26135f7

File tree

5 files changed

+68
-27
lines changed

5 files changed

+68
-27
lines changed

aspnetcore/fundamentals/minimal-apis.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ description: Provides an overview of Minimal APIs in ASP.NET Core
55
ms.author: wpickett
66
content_well_notification: AI-contribution
77
monikerRange: '>= aspnetcore-6.0'
8-
ms.date: 09/08/2025
8+
ms.date: 10/23/2025
99
uid: fundamentals/minimal-apis
1010
ai-usage: ai-assisted
1111
---
1212

13-
<!-- When working on this file, open all the LATEST VERSION MD files in ~/fundamentals/minimal-apis/includes/ and search for the target text -->
13+
<!--
14+
Editorial note: This file is a quick reference summary:
15+
- When working on this file, open all the LATEST VERSION MD files in ~/fundamentals/minimal-apis/includes/ and search for the target text.
16+
- Only include brief overviews, essential lists, and basic examples in this file.
17+
- Do NOT add detailed explanations, advanced scenarios, or troubleshooting—move those to dedicated include files (for example: parameter-binding8-10.md) and link to them from here if needed.
18+
- All in-depth content should be placed in the appropriate in-depth include file for maintainability and clarity.
19+
- Use H3 (###) for section headings within this include.
20+
-->
1421

1522
# Minimal APIs quick reference
1623

@@ -68,7 +75,7 @@ The <xref:System.Delegate> arguments passed to these methods are called "route h
6875

6976
## Parameter binding
7077

71-
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding8-10.md)]
78+
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding-summary8-10.md)]
7279

7380
## Json+PipeReader deserialization in minimal APIs
7481

aspnetcore/fundamentals/minimal-apis/includes/minimal-apis8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The <xref:System.Delegate> arguments passed to these methods are called "route h
5050

5151
## Parameter binding
5252

53-
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding8-10.md)]
53+
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding-summary8-10.md)]
5454

5555
## Responses
5656

aspnetcore/fundamentals/minimal-apis/includes/minimal-apis9.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The <xref:System.Delegate> arguments passed to these methods are called "route h
5050

5151
## Parameter binding
5252

53-
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding8-10.md)]
53+
[!INCLUDE [](~/fundamentals/minimal-apis/includes/parameter-binding-summary8-10.md)]
5454

5555
## Responses
5656

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:::moniker range=">= aspnetcore-8.0"
2+
3+
Parameter binding is the process of converting request data into strongly typed parameters that are expressed by route handlers. A binding source determines where parameters are bound from. Binding sources can be explicit or inferred based on HTTP method and parameter type.
4+
5+
Supported binding sources:
6+
7+
* Route values
8+
* Query string
9+
* Header
10+
* Body (as JSON)
11+
* Form values
12+
* Services provided by dependency injection
13+
* Custom
14+
15+
The following GET route handler uses some of these parameter binding sources:
16+
17+
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/WebMinAPIs/Program.cs" id="snippet_pbg" highlight="8-11":::
18+
19+
### Key parameter binding features
20+
21+
* **Explicit binding**: Use attributes like `[FromRoute]`, `[FromQuery]`, `[FromHeader]`, `[FromBody]`, `[FromForm]`, and `[FromServices]` to explicitly specify binding sources.
22+
* **Form binding**: Bind form values using `[FromForm]` attribute, including support for `IFormFile` and `IFormFileCollection` for file uploads.
23+
* **Complex types**: Bind to collections and complex types from forms, query strings, and headers.
24+
* **Custom binding**: Implement custom binding logic using `TryParse`, `BindAsync`, or the `IBindableFromHttpContext<T>` interface.
25+
* **Optional parameters**: Support nullable types and default values for optional parameters.
26+
* **Dependency injection**: Parameters are automatically bound from services registered in the DI container.
27+
* **Special types**: Automatic binding for `HttpContext`, `HttpRequest`, `HttpResponse`, `CancellationToken`, `ClaimsPrincipal`, `Stream`, and `PipeReader`.
28+
29+
---
30+
31+
**Learn more:** For detailed information on parameter binding including advanced scenarios, validation, binding precedence, and troubleshooting, see <xref:fundamentals/minimal-apis/parameter-binding>.
32+
33+
34+
:::moniker-end

aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8-10.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The parameters in the preceding examples are all bound from request data automat
3535

3636
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/WebMinAPIs/Snippets/Program.cs" id="snippet_ManualRequestBinding" highlight="3-5,12":::
3737

38-
### Explicit Parameter Binding
38+
## Explicit Parameter Binding
3939

4040
Attributes can be used to explicitly declare where parameters are bound from.
4141

@@ -49,7 +49,7 @@ Attributes can be used to explicitly declare where parameters are bound from.
4949
| `service` | Provided by dependency injection |
5050
| `contentType` | header with the name `"Content-Type"` |
5151

52-
#### Explicit binding from form values
52+
### Explicit binding from form values
5353

5454
The [`[FromForm]`](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) attribute binds form values:
5555

@@ -65,7 +65,7 @@ For more information, see the section on [AsParameters](#parameter-binding-for-a
6565

6666
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/IFormFile) is in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
6767

68-
#### Secure binding from IFormFile and IFormFileCollection
68+
### Secure binding from IFormFile and IFormFileCollection
6969

7070
Complex form binding is supported using <xref:Microsoft.AspNetCore.Http.IFormFile> and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> using the [`[FromForm]`](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute):
7171

@@ -77,13 +77,13 @@ For more information, see [Form binding in minimal APIs](https://andrewlock.net/
7777

7878
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/FormBinding) is in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
7979

80-
### Parameter binding with dependency injection
80+
## Parameter binding with dependency injection
8181

8282
Parameter binding for minimal APIs binds parameters through [dependency injection](xref:fundamentals/dependency-injection) when the type is configured as a service. It's not necessary to explicitly apply the [`[FromServices]`](xref:Microsoft.AspNetCore.Mvc.FromServicesAttribute) attribute to a parameter. In the following code, both actions return the time:
8383

8484
:::code language="csharp" source="~/release-notes/aspnetcore-7/samples/ApiController/Program.cs" id="snippet_min" highlight="8-9":::
8585

86-
### Optional parameters
86+
## Optional parameters
8787

8888
Parameters declared in route handlers are treated as required:
8989

@@ -127,7 +127,7 @@ The preceding code calls the method with a null product if no request body is se
127127

128128
See the [Binding Failures](#bf) section for more information.
129129

130-
### Special types
130+
## Special types
131131

132132
The following types are bound without explicit attributes:
133133

@@ -159,7 +159,7 @@ The following types are bound without explicit attributes:
159159

160160
<a name="rbs"></a>
161161

162-
#### Bind the request body as a `Stream` or `PipeReader`
162+
### Bind the request body as a `Stream` or `PipeReader`
163163

164164
The request body can bind as a [`Stream`](/dotnet/api/system.io.stream) or [`PipeReader`](/dotnet/api/system.io.pipelines.pipereader) to efficiently support scenarios where the user has to process data and:
165165

@@ -184,7 +184,7 @@ The following code shows the complete `Program.cs` file:
184184
* The request body isn't buffered by default. After the body is read, it's not rewindable. The stream can't be read multiple times.
185185
* The `Stream` and `PipeReader` aren't usable outside of the minimal action handler as the underlying buffers will be disposed or reused.
186186

187-
#### File uploads using IFormFile and IFormFileCollection
187+
### File uploads using IFormFile and IFormFileCollection
188188

189189
The following code uses <xref:Microsoft.AspNetCore.Http.IFormFile> and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> to upload file:
190190

@@ -194,7 +194,7 @@ Authenticated file upload requests are supported using an [Authorization header]
194194

195195
<a name="bind8"></a>
196196

197-
#### Binding to forms with IFormCollection, IFormFile, and IFormFileCollection
197+
### Binding to forms with IFormCollection, IFormFile, and IFormFileCollection
198198

199199
Binding from form-based parameters using <xref:Microsoft.AspNetCore.Http.IFormCollection>, <xref:Microsoft.AspNetCore.Http.IFormFile>, and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> is supported. [OpenAPI](xref:fundamentals/openapi/aspnetcore-openapi) metadata is inferred for form parameters to support integration with [Swagger UI](xref:tutorials/web-api-help-pages-using-swagger).
200200

@@ -212,7 +212,7 @@ For more information, see [Form binding in minimal APIs](https://andrewlock.net/
212212

213213
<a name="bindcc"></a>
214214

215-
### Bind to collections and complex types from forms
215+
## Bind to collections and complex types from forms
216216

217217
Binding is supported for:
218218

@@ -244,7 +244,7 @@ isCompleted: false
244244

245245
<a name="bindar"></a>
246246

247-
### Bind arrays and string values from headers and query strings
247+
## Bind arrays and string values from headers and query strings
248248

249249
The following code demonstrates binding query strings to an array of primitive types, string arrays, and [StringValues](/dotnet/api/microsoft.extensions.primitives.stringvalues):
250250

@@ -279,7 +279,7 @@ The following code binds to the header key `X-Todo-Id` and returns the `Todo` it
279279
280280
<a name="asparam7"></a>
281281

282-
### Parameter binding for argument lists with [AsParameters]
282+
## Parameter binding for argument lists with [AsParameters]
283283

284284
<xref:Microsoft.AspNetCore.Http.AsParametersAttribute> enables simple parameter binding to types and not complex or recursive model binding.
285285

@@ -319,15 +319,15 @@ Using a `struct` with `AsParameters` can be more performant than using a `record
319319

320320
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/arg-lists) in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
321321

322-
### Custom Binding
322+
## Custom Binding
323323

324324
There are three ways to customize parameter binding:
325325

326326
1. For route, query, and header binding sources, bind custom types by adding a static `TryParse` method for the type.
327327
1. Control the binding process by implementing a `BindAsync` method on a type.
328328
1. For advanced scenarios, implement the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface to provide custom binding logic directly from the `HttpContext`.
329329

330-
#### TryParse
330+
### TryParse
331331

332332
`TryParse` has two APIs:
333333

@@ -340,7 +340,7 @@ The following code displays `Point: 12.3, 10.1` with the URI `/map?Point=12.3,10
340340

341341
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/WebMinAPIs/Program.cs" id="snippet_cb":::
342342

343-
#### BindAsync
343+
### BindAsync
344344

345345
`BindAsync` has the following APIs:
346346

@@ -355,7 +355,7 @@ The following code displays `SortBy:xyz, SortDirection:Desc, CurrentPage:99` wit
355355

356356
<a name="bf"></a>
357357

358-
#### Custom parameter binding with `IBindableFromHttpContext`
358+
### Custom parameter binding with `IBindableFromHttpContext`
359359

360360
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
361361

@@ -381,7 +381,7 @@ You can also implement validation within your custom binding logic:
381381

382382
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/10.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
383383

384-
### Binding failures
384+
## Binding failures
385385

386386
When binding fails, the framework logs a debug message and returns various status codes to the client depending on the failure mode.
387387

@@ -393,7 +393,7 @@ When binding fails, the framework logs a debug message and returns various statu
393393
| Failure to deserialize JSON body |doesn't matter|body|400|
394394
| Wrong content type (not `application/json`) |doesn't matter|body|415|
395395

396-
### Binding Precedence
396+
## Binding Precedence
397397

398398
The rules for determining a binding source from a parameter:
399399

@@ -423,27 +423,27 @@ The rules for determining a binding source from a parameter:
423423
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
424424
1. The parameter is from the body.
425425

426-
### Configure JSON deserialization options for body binding
426+
## Configure JSON deserialization options for body binding
427427

428428
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.
429429

430-
#### Configure JSON deserialization options globally
430+
### Configure JSON deserialization options globally
431431

432432
Options that apply globally for an app can be configured by invoking <xref:Microsoft.Extensions.DependencyInjection.HttpJsonServiceExtensions.ConfigureHttpJsonOptions%2A>. The following example includes public fields and formats JSON output.
433433

434434
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/WebMinJson/Program.cs" id="snippet_confighttpjsonoptions" highlight="3-6":::
435435

436436
Since the sample code configures both serialization and deserialization, it can read `NameField` and include `NameField` in the output JSON.
437437

438-
#### Configure JSON deserialization options for an endpoint
438+
### Configure JSON deserialization options for an endpoint
439439

440440
<xref:Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync%2A> has overloads that accept a <xref:System.Text.Json.JsonSerializerOptions> object. The following example includes public fields and formats JSON output.
441441

442442
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/WebMinJson/Program.cs" id="snippet_readfromjsonasyncwithoptions" highlight="5-8,12":::
443443

444444
Since the preceding code applies the customized options only to deserialization, the output JSON excludes `NameField`.
445445

446-
### Read the request body
446+
## Read the request body
447447

448448
Read the request body directly using a <xref:Microsoft.AspNetCore.Http.HttpContext> or <xref:Microsoft.AspNetCore.Http.HttpRequest> parameter:
449449

0 commit comments

Comments
 (0)