I am learning about MudAutocomplete code from https://mudblazor.com/components/autocomplete#api and copy code to run test but I found error 'No overload for 'Search1' matches delegate 'Func<string, CancellationToken, Task<IEnumerable<string>>>''
<MudGrid>
<MudItem xs="12" sm="6" md="4">
<MudAutocomplete T="string" Label="US States" @bind-Value="value1" SearchFunc="@Search1" Variant="Variant.Outlined" />
</MudItem>
</MudGrid>
@code {
private string value1;
private string[] states =
{
"Alabama", "Alaska", "American Samoa", "Arizona",
"Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "District of Columbia", "Federated States of Micronesia",
"Florida", "Georgia", "Guam", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
"Louisiana", "Maine", "Marshall Islands", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi",
};
private async Task<IEnumerable<string>> Search1(string value)
{
// In real life use an asynchronous function for fetching data from an api.
await Task.Delay(5);
// if text is null or empty, show complete list
if (string.IsNullOrEmpty(value))
return states;
return states.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
}
How can I find solution ? Thank you.
MudBlazor Autocomplete component has two properties, SearchFunc
and SearchFuncWithCancel
.
If you want to use cancelation token, use the second one SearchFuncWithCancel
and in that case, you may want to create a method:
private async Task<IEnumerable<string>> Search1(string value, CancellationToken token) { ---All the stuff in method}
Otherwise, if you are using just SearchFunc
, then just delete CancellationToken
from method parameters and you should be fine.
private async Task<IEnumerable<string>> Search1(string value){}