How to get the selected value from autocomplete?

My autocomplete is defined as below:

<RadzenAutoComplete 
    @bind-Value=@searchText 
    Data=@accounts
    LoadData=@LoadData 
    TextProperty="@nameof(Account.Name)"
    Change=@onChange>

    <Template>
        ...
    </Template>
</RadzenAutoComplete>

With

string searchText = default!;
IEnumerable<Account> accounts = default!;

And

private void onChange(object value) {
    Account? account = value as Account;

    if (account != null)
    {
        OnAccountSelected(account);
    }
}

// LoadData omitted.

While debugging I can see that sometimes value is a string, sometimes it is an Account, but the check account != null always fail.

All I want is to get on the click event on an item in the results with the selected Account as the payload.

Hi @acmoune,

The value should always be a string (the property specified via TextProperty). You can't get the "whole" account from the AutoComplete component. If you need that I suggest using RadzenDropDown instead - it has built-in filter as you type. The other option is to find the account by its name:

var account = accounts.FirstOrDefault(a => a.Name == value.ToString());

Ok, I will try with the Dropdown. thanks.

If I understand correctly there is no proper way of implementing a search box as of now. Is thar correct?

We will do our best to add ValueProperrty to AutoComplete similar to the DropDown for our next update next week.

UPDATE: Unfortunately I spoke too soon - we can't do that without a breaking change. Instead of ValueProperty we will add SelectedItem which can be bound to get any of the item properties. We will update our examples as well.