I'm getting the following error with the dropdown control. It loads fine, populates the list fine, the initial values from the data are selected. But if I try to change the selection, I get the following:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
at Radzen.DropDownBase1.<SelectItem>d__100[[System.Collections.Generic.List1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
The data 'roles' is a List of string, the thing I'm trying to bind to 'editUser.roles' is also a List of string. I don't get what it's trying to cast to throw this error.
Is what I'm pointing out a bug in the RadzenDropDown control, or am I missing something about how it's meant to work? Can it work with lists or does it specifically need IEnumerable?
I can't change it from List of Role to IEnumerable of Role, because that breaks the EF mapping on the database, so I don't know whether that would fix it.
This doesn't work with entity framework 6 and Azure Cosmos Db. This is the error you get if you try that:
System.InvalidOperationException: 'The property 'ApplicationUser.Roles' could not be mapped because it is of type 'IEnumerable', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'
Where as it works perfectly fine as a list.
Is it within the realms of possibility in future versions of Radzen that dropdown could be a bit more flexible in what it'll bind to? A list implements IEnumerable after all.
Amazing, thank you, that's great. In the mean time I've worked around it with a non-mapped property on my model that sets the mapped one and then bound to that on the dropdown control e.g.:
public List<string> Roles { get; set; } = new List<string>();
[NotMapped]
public IEnumerable<string> RolesEnumerable
{
get
{
return this.Roles;
}
set
{
this.Roles = value.ToList();
}
}
That lets me work around it for now.
I'll hopefully try the updated version soon (though my partner is due to give birth any day now, so might be a while!)