Skip to content

Commit 3b1de9d

Browse files
authored
Fix moniker range + nits (#20016)
1 parent 375484b commit 3b1de9d

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

aspnetcore/mvc/models/model-binding.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,18 @@ For `Dictionary` targets, model binding looks for matches to *parameter_name* or
378378

379379
* selectedCourses["1050"]="Chemistry"
380380
* selectedCourses["2000"]="Economics"
381+
382+
::: moniker-end
381383

382-
::: moniker range="> aspnetcore-5.0"
384+
::: moniker range=">= aspnetcore-5.0"
383385

384386
## Constructor binding and record types
385387

386-
Model binding requires that complex types have a parameterless constructor. Both `System.Text.Json` and `Newtonsoft.Json` based input formatters support deserialization of classes that do not have a parameterless constructor.
388+
Model binding requires that complex types have a parameterless constructor. Both `System.Text.Json` and `Newtonsoft.Json` based input formatters support deserialization of classes that don't have a parameterless constructor.
387389

388-
C# 9 introduces record types which are a great way to succintly represent data over the network. ASP.NET Core adds support for model binding and validating record types with a single constructor.
390+
C# 9 introduces record types, which are a great way to succinctly represent data over the network. ASP.NET Core adds support for model binding and validating record types with a single constructor:
389391

390-
```C#
392+
```csharp
391393
public record Person([Required] string Name, [Range(0, 150)] int Age);
392394

393395
public class PersonController
@@ -397,23 +399,29 @@ public class PersonController
397399
[HttpPost]
398400
public IActionResult Index(Person person)
399401
{
400-
// ...
402+
...
401403
}
402404
}
405+
```
406+
407+
`Person/Index.cshtml`:
403408

404-
// Person/Index.cshtml
409+
```cshtml
405410
@model Person
406411
407412
Name: <input asp-for="Name" />
408413
...
409414
Age: <input asp-for="Age" />
410415
```
411416

412-
When validating record types, the runtime looks for validation metadata specifically on parameters rather than on properties.
417+
When validating record types, the runtime searches for validation metadata specifically on parameters rather than on properties.
413418

414419
::: moniker-end
415420

421+
::: moniker range=">= aspnetcore-3.0"
422+
416423
<a name="glob"></a>
424+
417425
## Globalization behavior of model binding route data and query strings
418426

419427
The ASP.NET Core route value provider and query string value provider:
@@ -530,6 +538,7 @@ This attribute's name follows the pattern of model binding attributes that speci
530538
* <xref:mvc/advanced/custom-model-binding>
531539

532540
::: moniker-end
541+
533542
::: moniker range="< aspnetcore-3.0"
534543

535544
This article explains what model binding is, how it works, and how to customize its behavior.

0 commit comments

Comments
 (0)