Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to use FluentAutocomplete when TOption is class object

$
0
0

I have two class models :

Country.cs

public class Country{    public long Id { get; set; }    public string Code { get; set; }    public string Name { get; set; }}

Airport.cs

public class Airport : BaseModel{    public long Id { get; set; }    public string IATA { get; set; }    public string ICAO { get; set; }    public string Name { get; set; }    public long CountryId { get; set; }}

In a form that creates/edits an airport object, I want to use FluentAutocomplete so the user can search and select a CountryId.

<FluentAutocomplete TOption="Country"                    Items="countries"                    AutoComplete="ComboboxAutocomplete.List"                    Label="Country"                    Placeholder="Select country"                    OptionText="@(c => c.Name)"                    OptionValue="@(c => c.Id.ToString())"                    @bind-value="SelectedCountry"                    Required Style="width: 80%" />

and the SelectedCountry variable :

private string? SelectedCountry{    get => Content.CountryId.ToString();    set {        if (long.TryParse(value, out var Id))        {            Content.CountryId = Id;        }    }}

The problem is in the setter of SelectedCountry, the value received is the value of currently selected Country.Name.

I've used another framework where the bound value can be set to "c => c.Id" but in Fluent it accepts string only.

How can I make the value selected @context.CountryId?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>