Hey,
i'm working with free Blazor components, i'm using RadzenDropDown with list of arbitrary objects, component is able to bind selected object to my model, just lovely. But then i tried Multiple atribute and
i don't know what i'm doing wrong, but i'm unable to get it work. It behaves really strange. First, my setup:
- .NET 6
- Blazor WebAssembly
- Radzen.Blazor v4.2.2 (it didn't worked in previous version either...)
First, i expected, that multiselect will be able to bind multiple arbitrary objects from data source to the model, which didn't work, because when i clicked dropdown item (or checkbox directly) checkbox will not get checkmark but the element is added to the model. Problem is, that i can click that same item multiple times, checkbox is never checked and each click will add that item to the model list. I thought it strange but because Blazor Dropdown component with multiple selection support is using only simple model values like IEnumerable<int> or IEnumerable<string> i thought that the values comparer, which checks if model already contains that item and either adds it or removes it can't work with arbitrary objects. Ok, so i simplified my model to just list of ints. But it doesn't work either, now every time i click a item, checkmark is not added and that same item is selected twice for the first click and then the number of model items are just multiplying. Anyway, i must be doing something really wrong, here is my code:
<RadzenDropDown
@bind-Value="multi"
Data="@items"
TValue="IEnumerable<int>"
ValueProperty="@nameof(SelectTest.Id)"
TextProperty="@nameof(SelectTest.Text)"
AllowClear
Multiple
/>
@code {
public class SelectTest
{
public int Id { get; set; }
public string? Text { get; set; }
public bool More { get; set; }
}
private readonly IEnumerable<SelectTest> items = Enumerable
.Range(1, 20)
.Select(x => new SelectTest {
Id = x,
Text = $"Test #{x}",
More = x % 2 == 0
});
private IEnumerable<int>? multi;
}
State of UI after i opened dropdown and clicked on "Test #1" (also note, that i got chips even if i didn't specify them in attributes and they sould be off by default):