dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.46k stars 10.03k forks source link

The Select Tag Helper not select an empty value when the property is null #41803

Open ultimaweapon opened 2 years ago

ultimaweapon commented 2 years ago

Is there an existing issue for this?

Describe the bug

The Select Tag Helper not select an empty value when Reason is null for the following model:

public sealed record DisableEmployee(string Name, [Required] EmployeeDisabledReason? Reason, DateTime EffectiveDate);

Definition of EmployeeDisabledReason:

public enum EmployeeDisabledReason
{
    Resigned = 0,
}

View:

<select id="disable-reason" class="form-select" asp-for="Reason" asp-items="Html.GetEnumSelectList<EmployeeDisabledReason>()">
  <option value="" disabled>Select a reason</option>
</select>

Result HTML:

<select id="disable-reason" class="form-select" name="Reason">
  <option value="" disabled="">Select a reason</option>
  <option value="0">Resigned</option>
</select>

Expected Behavior

I expect the first option that have the empty value have selected attribute applied. e.g.:

<select id="disable-reason" class="form-select" name="Reason">
  <option value="" selected="" disabled="">Select a reason</option>
  <option value="0">Resigned</option>
</select>

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.102

Anything else?

.NET SDK (reflecting any global.json):
 Version:   6.0.102
 Commit:    49861cb924

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.102/

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  6.0.102 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.