I have a Blazor application where I am using the Radzen components. Specifically, I am using the drop down component. I am running into an issue where I am unable to bind the Data to a list of floats.
<RadzenDropDown @bind-Value="@model.modelValue" Data="options"></RadzenDropDown>
@code {
List<float> options;
options.Add(1);
options.Add(2);
...
}
When I try this, I get the following error:
cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'
I know it is possible to do the following to make it work:
<RadzenDropDown @bind-Value="@model.modelValue" TextProperty="Text" Data="@(options.Select(s => new { Text = s, Value = s }))"></RadzenDropDown>
I'd like to avoid that because I have an modal that allows the user to manually enter a value and I can't get that value to show if I have to convert my float value to an object.
Is there anyway to bind to primitives?
The component is looking for an IEnumerable<object>
, not float
. You can pass in a List<object>
(since it implements IEnumerable
), and then put float
s in it, since float
's are object
s. Here's a full working example.
@page "/radzentest"
<RadzenDropDown TValue="float" Data="Options"></RadzenDropDown>
@code {
List<object> Options = new List<object>();
protected override void OnInitialized()
{
Options.Add(1.1f);
Options.Add(2.5f);
}
}
Result:
I'm not sure if there is a technical reason why Radzen couldn't do it that I don't understand, but it seems like a miss on their part to not have it be IEnumerable<T>
instead of IEnumerable<object>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With