Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
If you create a InputSelect control that is bound (via @bind-Value) to a bool?, it does not work in the same way as InputSelect bound to other nullable types (say int or Enum), and it never displays the null value correctly, but always shows the "false" value.
Expected Behavior
When a Nullable is bound to an InputSelect, the option with value="" should be bound to the null value. This is how other nullable types work with InputSelect, and also is the most useful.
If the model has null, then the option with value="" should be displayed when the form initially shows.
If the select is manually set to the option with value="", then that value should continue to be displayed.
Steps To Reproduce
@page "/"
<EditForm Model="Model" OnValidSubmit="Submit">
<p>
<label>What is your favorite color?</label>
<InputSelect @bind-Value="Model.FavoriteColor">
<option value="">Select a Color</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</InputSelect>
</p>
<p>
<label>How many legs do you have?</label>
<InputSelect @bind-Value="Model.NumberOfLegs">
<option value="">Select a Number</option>
<option value="1">1</option>
<option value="2">2</option>
</InputSelect>
</p>
<p>
<label>Are you awesome?</label>
<InputSelect @bind-Value="Model.Awesome">
<option value="">Select Yes or No</option>
<option value="true">Yes</option>
<option value="false">No</option>
</InputSelect>
</p>
<button>Submit</button>
</EditForm>
@code {
enum Color { Red, Green, Blue };
class InputModel
{
public Color? FavoriteColor { get; set; } = null;
public int? NumberOfLegs { get; set; } = null;
public bool? Awesome { get; set; } = null;
}
InputModel Model = new InputModel();
void Submit()
{
Console.WriteLine($"Color: {Model.FavoriteColor} Legs: {Model.NumberOfLegs} Awesome: {Model.Awesome}");
}
}
When this form is initially shown, the Favorite Color and Number of Legs selects show the "Select..." option, but the Awesome select shows "No". In addition, any attempt to set the "Awesome" select to "Select Yes or No" has it change immediate back to No.
Exceptions (if any)
No response
.NET Version
8.0.200
Anything else?
I think the fix is to change the src/Components/Web/src/Forms/InputSelect.cs implementation of FormatValueAsString to something like:
protected override string? FormatValueAsString(TValue? value)
{
if (typeof(TValue) == typeof(bool)) {
return (bool)(object)value! ? "true" : "false";
}
else if (typeof(TValue) == typeof(bool?)) {
if (value == null)
return null;
else
return (bool)(object)value ? "true" : "false";
}
return base.FormatValueAsString(value);
}
Luckily this method is protected, so I can fix this in the meantime by creating my own component:
public class BetterInputSelect<TValue>: InputSelect<TValue>
{
protected override string? FormatValueAsString(TValue? value)
{
if (typeof(TValue) == typeof(bool)) {
return (bool)(object)value! ? "true" : "false";
}
else if (typeof(TValue) == typeof(bool?)) {
if (value == null)
return null;
else
return (bool)(object)value ? "true" : "false";
}
return base.FormatValueAsString(value);
}
}
But I think the actual InputSelect.cs should be fixed.
Activity
robinwilson16 commentedon Dec 11, 2024
Please could this be fixed as otherwise it makes forms not really work if you want to require users to pick a value:

robinwilson16 commentedon Dec 11, 2024
Thanks @petergolde I can confirm your fix works and makes it work as I believe is intended so that it picks the "" option for
bool?and not false.Perhaps Microsoft can merge this fix into the main code for Christmas!
Inspirateur commentedon Apr 23, 2025
Just lost 2 work hours running into this. This should be a core issue and it's still open after 1 year ?
Sorry for being salty but this really feels like it should be fixed already.
m-e-lloyd commentedon Jan 23, 2026
Same issue still persists. Can confirm that the suggested fix works nicely.
robinwilson16 commentedon Jan 25, 2026
Please can this bug be patched in .NET so
bool?selects work correctly without defaulting to the false option.It didn't used to do this so I think was broken with .NET 8 but remains broken in .NET 10 (and .NET 9).
Perhaps it can be fixed in .NET 11 before next Christmas?!
Having yes/no options on web forms that are NULL and required is a pretty standard requirement and shouldn't need people to work around the bug after troubleshooting their code and realising it is the framework at fault.
m-e-lloyd commentedon Jan 25, 2026
Have submitted a PR to fix this, hopefully it gets picked up.
sweeperq commentedon Mar 4, 2026
Just ran into this today. Apparently, it is still an issue almost 2 years later.
amelia635 commentedon May 6, 2026
Also ran into this today.
thomak-dev commentedon Jul 6, 2026
Please fix this already, I am tired of creating tristate enums just because of this
silverlight-enjoyer commentedon Aug 26, 2026
Chiming into say that I also am running into this and is quite annoying.