Select Tag Helper Should Always Honor Overrides from an Explicit Multiple Attribute
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is your feature request related to a problem? Please describe.
In a project I'm working on, I'm offering a global configuration setting (`EnableUserMultiComputerAssignment`) to allow a `User` to be assigned to one or more `Computer`s. Based on the setting's value I want to present a single or a multi select. The problem I'm running into is that because I am always passing an `IEnumerable` for the `asp-for` attribute, the current implementation of select tag helper always defaults to a multi-select even when I try to override the `multiple` attribute.
Looking at the source code for select tag helper it always sets `_allowMultiple` if `asp-for` is an `IEnumerable`.
I currently have to do the following to achieve the result I want:
```html
Computers
@if (Model.Settings.EnableUserMultiComputerAssignment) {
} else {
}
```
And the model looks like this:
```c#
public sealed class User {
private Guid? _computerId;
public Guid? ComputerId {
get => _computerId ?? ComputerIds.FirstOrDefault();
init => _computerId = value;
}
public IEnumerable ComputerIds { get; init; } = new List();
}
```
### Describe the solution you'd like
I want to be able to override the tag helper if I explicitly set the `multiple` attribute:
```html
Computers
```
Contributor guide
Assessment
This issue has not been assessed yet.