Keep receiving the following error Cast not valid when switching values
OrderStyle is an enum with 3 values
public enum OrderStyle {Simple,Fast,Slow}
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[T].SelectItem (System.Object item, System.Boolean raiseChange) <0x39f0980 + 0x0024a> in <filename unknown>:0 at Radzen.Blazor.RadzenDropDown1[TValue].OnSelectItem (System.Object item) <0x3dd46e0 + 0x001a2> in :0
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x3dd5a90 + 0x000da> in :0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x3818ba0 + 0x000b6> in :0
I can see that this works in general and I've managed to correct my case.
One perhaps not expected behavior was that because my enum values have numbers associated to them
the method suggested will cause the number to be displayed in the drop, then rendered as the name representation once selected.
I guess Enum.GetValues works differently in server-side blazor and returns string values. Frankly I am not sure this is related to Radzen. What happens when you use a regular <select>?
@code {
// define a class to support the dropdown
public class EnumMyTypes
{
public MyStuff.MyTypes EnumValue { get; set; }
public string EnumName { get; set; }
}
// list for the dropdown
List MyTypes { get; set; } = new List();
protected override void OnInitialized()
{
try
{
// load the list
foreach (MyStuff.MyTypes item in Enum.GetValues(typeof(MyType)))
{
MyTypes.Add(new EnumMyTypes { EnumName = item.ToString(), EnumValue = item });
}