dotnet / dotnet/aspnetcore

CultureInfo difference in ValueProviderFactory implementations

Open
#55,920 0 comments 2 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When I send a request with QueryString, it does not bind correctly for the DateTime type. Upon investigation, I found that `CultureInfo.InvariantCulture` is used within the `QueryStringValueProviderFactory`. There is no issue when `CultureInfo.CurrentCulture` is used. Why is there a difference in the use of CultureInfo among ValueProviderFactory implementations? The findings are as follows.

#### CultureInfo.InvariantCulture
https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/QueryStringValueProviderFactory.cs#L27
https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/JQueryQueryStringValueProviderFactory.cs#L26
https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/JQueryQueryStringValueProviderFactory.cs#L26

#### CultureInfo.CurrentCulture
https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/FormValueProviderFactory.cs#L57
https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/JQueryFormValueProviderFactory.cs#L57

### Expected Behavior

The model binding process should be performed according to the `CultureInfo.CurrentCulture` information in which the application is running.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.205

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.