DropDown data binding issue

Hello @Team.

After some code refactoring, an issue started occuring in the following DropDown:

<RadzenDropDown @bind-Value=@(FilterEntityTypes) AllowClear="true" Data=@(Language.DocumentEntityTypesAlternative) Multiple="true" Name="EntityTypesDropDown"
SelectAllText=@(Language.TextTypes.Value(TextType.All)) Style="display: block; width: 100%;" TextProperty="Value" ValueProperty="Key" />

The issue is that it does not bind values properly when the Data is DocumentEntityTypes.

DocumentEntityTypes
DropDownCurrent

DocumentEntityTypesAlternative
DropDownAlternative

The important code in the component:

IEnumerable<int?> FilterEntityTypes;

Here's the code in Language class:

public Dictionary<int?, string> DocumentEntityTypes =>
    EntityTypes.Where(x => x.Key != (int)EntityType.Vehicle).ToDictionary(x => x.Key, x => x.Value);

public readonly Dictionary<int?, string> DocumentEntityTypesAlternative = new() {
    { (int?)EntityType.Unknown, "Desconhecida" },
    { (int?)EntityType.Company, "Empresa" },
    { (int?)EntityType.Person, "Pessoa" }
};

public readonly Dictionary<int?, string> EntityTypes = new() {
    { (int?)EntityType.Unknown, "Desconhecida" },
    { (int?)EntityType.Company, "Empresa" },
    { (int?)EntityType.Person, "Pessoa" },
    { (int?)EntityType.Vehicle, "Veículo" }
};

There are no errors thrown in the console log. Radzen.Blazor 3.12.5.

Not sure at what point this might worked however DocumentEntityTypes is expression that will be evaluated every time Data property is accessed, resulting in different items for each evaluation - no selection state can be saved this way. Here is how to rework this:

2 Likes