dotnet / dotnet/aspnetcore

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

Open
#41,803 1 comment 0 reactions 0 assignees View on GitHub
area-mvc investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

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

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

Definition of `EmployeeDisabledReason`:

```csharp
public enum EmployeeDisabledReason
{
Resigned = 0,
}
```

View:

```razor

Select a reason

```

Result HTML:

```html

Select a reason
Resigned

```

### Expected Behavior

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

```html

Select a reason
Resigned

```

### 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
```

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.