hello community I am trying to use the select2 component in blazor, I took an example from github but the truth is I am lost in how to fill the component with the records from the database
this is the razor page and this is the component:
<span>Simple string example</span>
<Select2 TItem="string"
Id="simple-string-example"
Data="@SimpleStringList"
@bind-Value="@ValueSelected">
</Select2>
<span>Currently selected value: @ValueSelected</span>
<br />
@code {
private EditContext EditContext { get; set; }
private Select2<SomeInnerObject> ProvidedSelect2Ref { get; set; }
public SomeObject FakeObject { get; set; } = new SomeObject { SomeName = "Name" };
private List<string> SimpleStringList { get; set; } = new List<string>();
private List<SomeInnerObject> InnerObjectList { get; set; }
private string ValueSelected { get; set; }
private SomeInnerObject FooObject = new SomeInnerObject { InnerName = "Inner Foo" };
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (firstRender)
{
SimpleStringList.Add("Foo");
SimpleStringList.Add("Bar");
SimpleStringList.Add("Baz");
InnerObjectList = new List<SomeInnerObject> { FooObject, new SomeInnerObject { InnerName = "Inner bar" } };
for (var i = 0; i < 100; i++)
InnerObjectList.Add(new SomeInnerObject { InnerName = $"Inner bar{i}" });
EditContext = new EditContext(FakeObject).AddDataAnnotationsValidation();
StateHasChanged();
}
}
}
How could you fill the component with records from the database, calling an api in a controller, something like this:
private async Task<IEnumerable<Persona>> BuscarPersonas(string searchText)
{
var responseHttp = await repositorio.Get<List<Persona>>($"api/Personas/buscar/{searchText}");
return responseHttp.Response;
}
}

