MudBrazor自动完成不区分大小写搜索.NET 6 Blazor服务器应用程序



嗨,我在使MudBLazor自动完成搜索给定列表时遇到问题。此国家/地区列表是以列表形式从服务中获取的。我尝试过将StringComparison.InvariantCultureIgnoreCase更改为其他文化,但没有成功!

这是代码:我真的不明白为什么自动完成不返回与搜索字符串(值(匹配的较小列表。它只与区分大小写的字母匹配,比如阿尔巴尼亚而不是阿尔巴尼亚。

<MudCard Style="margin-bottom: 20px; width: 600px;">
<MudCardContent>
<label>Sending from:</label>
<MudAutocomplete T="string" Label="Country" @bind-Value="@userCountry" SearchFunc="@SearchFromCountries" />
</MudCardContent>
</MudCard>
@code {
private string userCountry, userToCountry;
public IEnumerable<CountriesCurrencies> countries;

private List<string> countryList;
protected override async Task OnInitializedAsync()
{
userCountry = await countryService.GetUserCountry(userId);
countries = await countryService.GetCountriesList();
countryList = GetCountriesList();
}
private List<string> GetCountriesList()
{
countryList = new List<string>();
foreach (var country in countries)
{
countryList.Add(country.Country);
}
return countryList;
}
private async Task<IEnumerable<string>> SearchFromCountries(string value)
{
await Task.Delay(5);
if (string.IsNullOrEmpty(value))
return countryList;
return await Task.FromResult(countryList.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase)));
}

按如下方式重新编码,并检查是否返回了正确的列表:

private Task<IEnumerable<string>> SearchFromCountries(string value)
{
if (string.IsNullOrEmpty(value))
return countryList;
var list = countryList.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
// break point here to check what you are returning
return Task.FromResult(list);
}

最新更新