Skip to content

Commit d74506c

Browse files
pranavkmRick-Andersonscottaddie
authored
Add notes about behavior changes to model binding in 5.0 (#19971)
* Add notes about behavior changes to model binding in 5.0 * Update 31-to-50.md * Apply suggestions from code review Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com> Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
1 parent 8c4f7a4 commit d74506c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

aspnetcore/migration/31-to-50.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,24 @@ As part of the move to ".NET" as the product name, the Docker images moved from
120120
## Review breaking changes
121121

122122
For breaking changes from .NET Core 3.1 to .NET 5.0, see [Breaking changes for migration from version 3.1 to 5.0](/dotnet/core/compatibility/3.1-5.0). ASP.NET Core and Entity Framework Core are also included in the list.
123+
124+
## Changes to model binding in ASP.NET Core MVC and Razor Pages
125+
126+
### DateTime values are model bound as UTC times
127+
128+
In ASP.NET Core 3.1 and earlier, `DateTime` values were model bound as local time where the timezone was determined by the server. `DateTime` values bound from input formatting (JSON) and `DateTimeOffset` values were bound as UTC timezones. In ASP.NET Core 5.0 and later, model binding consistently binds `DateTime` values with the UTC timezone.
129+
130+
To retain the previous behavior, remove the `DateTimeModelBinderProvider` as part of the application startup:
131+
132+
```csharp
133+
services.AddControllersWithViews(options => options.ModelBinderProviders.RemoveType<DateTimeModelBinderProvider>());
134+
```
135+
136+
### ComplexObjectModelBinderProvider \ ComplexObjectModelBinder replace ComplexTypeModelBinderProvider \ ComplexTypeModelBinder
137+
138+
As part of adding support for model binding record types, the `ComplexTypeModelBinderProvider` is annotated as obsolete and is no longer registered by default. Applications that previously relied on the presence of the `ComplexTypeModelBinderProvider` in the `ModelBinderProviders` collection need to be updated to reference the new binder provider:
139+
140+
```diff
141+
- var complexModelBinderProvider = options.ModelBinderProviders.OfType<ComplexTypeModelBinderProvider>();
142+
+ var complexModelBinderProvider = options.ModelBinderProviders.OfType<ComplexObjectModelBinderProvider>();
143+
```

0 commit comments

Comments
 (0)