In the demo of dropdown with multiple selection the ValueProperty CustomerID is a string.
I'm trying to set similar example, but in my case, the property I'm using as ValueProperty is an integer.
For the @bind-value, if I assign an IEnumerable<string> it will thrown a invalid cast operation. If I assign a IEnumerable<int> it doesn't thrown any exception, but I can't select (check) any value.
Is there a limitation in this feature that only works with String values?
<RadzenDropDown Name="Workspace" Multiple="true" Data="@(workspaces.Where(x => x.BuildingId == BuildingId))" TextProperty="Name" ValueProperty="WorkspaceId" @bind-Value="@selectedWorkspaceIds" Placeholder="Select..." Class="w100p" />
IEnumerable<int> selectedWorkspaceIds;
public class Workspace
{
public int WorkspaceId { get; set; }
public string Name { get; set; }
public int BuildingId { get; set; }
}
Thank you for you prompt reply and confirmation.
I refactored my code and somehow it works as expected. It's hard to say what was going in the way of the dropdown events.
Just now I noticed that combining Cascading DropDowns with Multiple selection does not work.
In your example, you set Data="@(workspaces)" , while I am actually using Data="@(workspaces.Where(x => x.BuildingId == BuildingId))" because the list of "workspaces" needs to be refreshed if the user selects another "building" in the previous dropdown.
I still worked out my way by setting Data="@(workspaces)" in the "workspaces" dropdown and setting a method at the Change event callback in the "buildings" dropdown to update the list of workspaces.
Is this something that can be improved in a future release of the components?
In my tests, when having a cascading dropdown and the second (child) dropdown is of type "multi selection", I can't select any option. The options are listed, but the checkboxes never become "checked".
Could you give it a try if you have time?
<RadzenDropDown
Name="Building"
Data="@buildings"
TextProperty="Name"
ValueProperty="BuildingId"
@bind-Value="@BuildingId"
/>
<RadzenDropDown
Name="Workspace"
Multiple="true"
Data="@(workspaces.Where(x => x.BuildingId == BuildingId))"
TextProperty="Name"
ValueProperty="WorkspaceId"
@bind-Value="@selectedWorkspaceIds"
/>
@code {
[Parameter]
public int BuildingId { get; set; }
IEnumerable<int> selectedWorkspaceIds;
IEnumerable<Building> buildings;
IEnumerable<Workspace> workspaces;
protected override async Task OnInitializedAsync()
{
buildings = dbContext.Buildings;
workspaces = dbContext.Workspaces;
// call for an authentication-related async method
}
}
public class Building
{
public int BuildingId { get; set; }
public string Name { get; set; }
public ICollection<Workspace> Workspaces { get; set; }
}
public class Workspace
{
public int WorkspaceId { get; set; }
public string Name { get; set; }
public int BuildingId { get; set; }
public Building Building { get; set; }
public ICollection<Reservation> Reservations { get; set; }
}