Niestandardowe elementy w liście <MudAutocomplete>

0

Dzień dobry,

mam klasę o poniższej strukturze:

IList<Kontrahent> Items = new List<Kontrahent>();

public class Kontrahent
{
    public int Id { get; set; }
    public string? Imie { get; set; }
    public string? Nazwisko { get; set; }
    public string? Telefon { get; set; }
}

Do której wczytywane są dane za pomocą poniższego polecenia:

protected override async Task OnInitializedAsync()
{
    Items = await baza.GetOfCustomers();
}

Teraz jak zrobić aby w poleceniu <MudAutocomplete> podpowiadała się cała nazwa z połączenia kontrahent.Imie oraz kontrahent.Nazwisko, a po wyborze konkretnej pozycji pobrało mi dane z kontrahent.ID

Poniżej coś próbowałem zrobić, ale zbytnio nie wychodzi :(

<MudAutocomplete T="Kontrahent" Label="Kontrahent:" SearchFunc="@SearchItem" Required="true" />

  private async Task<IEnumerable<Kontrahent>> SearchItem(string value)
  {
      if (string.IsNullOrEmpty(value))
      {
          return Items;
      }
      else
      {
      //    await ReadAutoCompleteData(value);
      }
      return Items.Where(x => x.Imie != null && x.Nazwisko.Contains(value, StringComparison.InvariantCultureIgnoreCase));
  }

Aktualizacja:
Mój problem udało mi się rozwiązać. Może komuś przyda się jak wzór.

<MudAutocomplete T="Kontrahent" ValueChanged="OnValueChanged" Label="Kontrahent:" SearchFunc="@SearchItem" ToStringFunc="@(e=> e==null?null : $"{e.Imie} {e.Nazwisko} - tel: {e.Telefon}")" Strict="false" Required="true" />

@code {

    List<Kontrahent> Items = new List<Kontrahent>();

    public void OnValueChanged(Kontrahent args)

    {

        Console.WriteLine("ID:" + args.Id);

    }

    private async Task<IEnumerable<Kontrahent>> SearchItem(string value)
    {
        if (string.IsNullOrEmpty(value))
        {
            return Items;
        }
        return Items.Where(x => x.Imie.Contains(value, StringComparison.InvariantCultureIgnoreCase));
    }


    protected override async Task OnInitializedAsync()
    {
        Items = await baza.GetOfCustomers();
    }


Dodatkowo jeżeli chcemy aby szukało nam wartości zarówno po Imieniu, Nazwisku oraz Telefonie to modyfikujemy to w następujący sposób:

 return Items.Where(x => x.Imie.Contains(value, StringComparison.InvariantCultureIgnoreCase) || x.Nazwisko.Contains(value, StringComparison.InvariantCultureIgnoreCase) || x.Telefon.Conta

0

w normalnym C# string nie potrzebuje pytajnika. W blazorze jest inaczej ?

1 użytkowników online, w tym zalogowanych: 0, gości: 1