Default value and clear selection of MudSelect
See original GitHub issueI have two MudSelects, one with type int and one with the type string:
<MudGrid Spacing="2">
<MudItem xs="12" sm="6" md="3">
<MudSelect T="int"
ValueChanged="ChangeFilterSystem"
Label="@(CurrentFilter.SystemIds != null ? "System" : "Loading..")"
Variant="Variant.Outlined"
Strict="true"
Dense="true"
OffsetY="true">
@if (CurrentFilter.SystemIds != null)
{
<MudSelectItem T="int" Value="0">All system-ids</MudSelectItem>
foreach (var system in CurrentFilter.SystemIds)
{
<MudSelectItem T="int" Value="@system">@system.ToString()</MudSelectItem>
}
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6" md="3">
<MudSelect T="string"
ValueChanged="ChangeFilterDepartment"
Label="@(CurrentFilter.Departments != null ? "Department" : "Loading..")"
Variant="Variant.Outlined"
Dense="true"
OffsetY="true">
@if (CurrentFilter.Departments != null)
{
<MudSelectItem T="string" Value="@("0")">All departments</MudSelectItem>
foreach (var department in CurrentFilter.Departments)
{
<MudSelectItem T="string" Value="@department">@department</MudSelectItem>
}
}
</MudSelect>
</MudItem>
</MudGrid>
And they are rendered like this:

Questions:
- MudSelect with type int takes the default value which I’ve given, “All system-ids”, but why can’t the MudSelect with type string take the default value of “All departments”? Is there a way for MudSelects with type string to be given a default value?
- Is there a way to clear the selection? To make it look like nothing is selected. Like in the MudSelect for Department in the attached image.
Best Regards Johan
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
MudSelect - how do I set default value #3014
To set the default value, you can set this on the variable that holds your value ( @bind-Value="@_Driver.FirstName" ). Something like this (I ......
Read more >How do I get default values to appear in MudBlazor ...
I'm using MudBlazor to create a component to select multiple items in a MudSelect. When I pre-populate values they don't appear in the ......
Read more >MudSelect<T> API
Name Type Default
SelectedValues IEnumerable
Text string null
Value T null
Read more >How do I set the default value in select control?
The property value in the select control can be used to set the default value in select control.
Read more >Clear the value (selection) of a combobox, dropdown, input
In Blazor, you clear the value of an input (such as a combobox, textbox, doropdownlist, date picker and so on) by changing its...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@johanthorild
Hi!
I understand what you mean, the behaviour is different because the different datatypes. Int works pretty much by accident and string does not because of nullchecks.
I’ve provided an example with your code on how you can do this (skipped some stuff to reproduce easier).
https://try.mudblazor.com/snippet/QkQlkdEIWbTaMCnY
Code here if you have issues with the app:
Thanks for using MudBlazor
EDIT: missed your second question, reset by choosing a value that is not in your value list! See example (I was too lazy to add buttons)
Well done! Thanks alot. The selects now work as I intended.
Love this framework, great work! Hope MudBlazor get the attention that it deserves.