nss
July 12, 2020, 4:23am
1
I am getting 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) <0x4770518 + 0x0024a> in <filename unknown>:0 at Radzen.Blazor.RadzenDropDown
1[TValue].OnSelectItem (System.Object item) <0x476f770 + 0x001a2> in :0
at
I am using Blazor WebAssembly(3.2) and using Radzen drop down inside editform
<RadzenDropDown id="CountryName" AllowClear="true" TValue="string" Placeholder="Select..."
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
Data="@countryList" TextProperty="Country_Name" ValueProperty="countryiD_PK" @bind-Value="_registerModel.CountryName" />
Note: that countryiD_PK is a guid value.
I am trying to build cascading drop downs for Country,State & City.
enchev
July 12, 2020, 4:53am
2
bind-Value will attempt to set ValueProperty value to specified property. You cannot set GUID value to string property.
nss
July 14, 2020, 1:02pm
3
Well i corrected my table to appropriate GUID, but still getting the error, why now ?
<RadzenDropDown id="CountryName" AllowClear="true" TValue="Guid" Placeholder="Select..." Style="display:block"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
Data="@countryList" TextProperty="Country_Name" ValueProperty="CountryID_PK"
@bind-Value="_Organization.CountryID_FK"
Change="@SelectedCountryChangeEvent"
SelectedItemChanged="@(obj => SelectedCountryChanged(obj))" />
@countrylist
has Country_Name(String) & CountryID_PK (GUID)
OrgTable
CountryID_FK (GUID)
nss
July 15, 2020, 2:52pm
4
Any insight into how to fix this ?
Can i do explicit cast using lambdas or other options to manually do it ?
enchev
July 15, 2020, 2:56pm
5
I cannot tell why you get this exception from the info provided so far. If you have Radzen subscription you can send us your application to info@radzen.com .
nss
July 15, 2020, 2:57pm
6
At this time i am just exploring Radzen, don't have any subscription.
Scott
July 26, 2020, 4:12am
7
I just ran across the same issue, but no subscription for me either.
Mine are custom objects: Alliance & Power
private Alliance selectedAlliance;
private Power selectedPower;
private async Task CreateGameAlliance() => await dialogService.OpenAsync("New Game Alliance", ds =>
@<RadzenCard Style="padding: 20px;">
<div class="row">
<div class="col-md-12">
<h3>Select a power to add to an alliance</h3>
<div>
<RadzenDropDown @bind-Value="@selectedAlliance" AllowClear="true" Data="@alliances" TValue="Alliance" TextProperty="Name" ValueProperty="Id" />
</div>
<div>
<RadzenDropDown @bind-Value="@selectedPower" AllowClear="true" Data="@powers" TValue="Power" TextProperty="Name" ValueProperty="Id" />
</div>
<RadzenButton ButtonStyle="ButtonStyle.Secondary" Click="SaveGameAlliance" Text="Save" Style="margin-top: 20px; width: 150px;"></RadzenButton>
</div>
</div>
</RadzenCard>);
enchev
July 26, 2020, 5:49am
8
You can check my replies in this thread. Bind Value will attempt to set ValueProperty value to your page property. I see that ValueProperty in your case is Id which most probably is some number while selectedAlliance is an object
@Scott , you can try not setting ValueProperty. When you set it @bind-Value will be set to whatever the ValueProperty of the selected data item is.
Scott
July 26, 2020, 7:51pm
10
Thank you for helping me understand the behavior of this component. I must have missed that earlier.
1 Like
Scott
July 26, 2020, 7:54pm
11
I took your advice of removing ValueProperty and I was able to bind the whole object to my variable. Thank you.
1 Like
I am facing similar issue. The Data is coming as a List of Objects which have ID(Guid) and Name.
How to set Guid to ValueProperty?
<RadzenDropDown AllowClear="true" AllowFiltering="true"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TValue="Guid"
LoadData="FilterRegionsList" Placeholder="Select..."
Multiple="true" MaxSelectedLabels="1"
Data=@RegionsList
TextProperty="Name"
ValueProperty="RegionID" Style="width:95%">
</RadzenDropDown>
RegionsList contais List of regions(ID : Guid and Name : String)
the issue is easy
<RadzenDropDownDataGrid TValue="Customer" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowFiltering="true" AllowClear="true"
@bind-Value="@currentCustomer"
Data=@customerList
TextProperty="Name"
Style="width: 50%"/>
define a private value "Customer? currentCustomer"
define : List customerList (with some content from db or some source)
TextProperty is the content you see in the combobox (Customer.Name)
Whenever you change something in the box it will pick the right item for you and put it in:
currentCustomer
Radzen is fun!