dotnet / dotnet/aspnetcore

Asp-for and Date Inputs not showing the stored value by default

Open
#22,182 2 comments 2 reactions 0 assignees View on GitHub
affected-very-few area-mvc bug feature-mvc-razor-views investigate severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug
When using an asp-for input, if displaying a default value (for example an edit form), by default unlike with strings or numbers, the date is not available and it's blank. To fix this you currently have to overwrite the `value=` attribute to inject the YYYY-MM-DD. Based on how other values are handled, this should be done implicitly. The bug is that instead of YYYY-MM-DD, you get a C# style DateTime string which isn't supported by the HTML5 standard. It needs to be converted before being passed to the user. I noticed that a DateTime input is not included in the MVC unit tests.

```

```
### To Reproduce
Create a form using asp-for tag helper that modifies a stored date object.

### Further References:
I found the following information when tracking down this bug.
* https://stackoverflow.com/a/9519493/6481581
* https://tools.ietf.org/html/rfc3339
* https://www.w3.org/TR/2011/WD-html-markup-20110405/input.date.html#input.date.attrs.value

### Further technical details
```
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.202
Commit: 6ea70c8dca

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.202\

Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6

.NET Core SDKs installed:
3.1.101 [C:\Program Files\dotnet\sdk]
3.1.200 [C:\Program Files\dotnet\sdk]
3.1.202 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

```

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.