typeahead - Blazored Typeahead ConvertMethod 不起作用
问题描述
我想使用 Blazored.Typeahead 组件,但由于 ConvertMethod 它返回此错误:
严重性代码 描述 项目文件行抑制状态错误 CS0411 方法 'TypeInference.CreateBlazoredTypeahead_0<TItem, TValue> 的类型参数(RenderTreeBuilder, int, int, Func<string, Task<IEnumerable>>, int, Func<TItem, TValue>, int, TValue, int, EventCallback, int, Expression<Func>, int, RenderFragment, int, RenderFragment)' 不能从用法中推断出来。尝试明确指定类型参数。
<BlazoredTypeahead SearchMethod="GetRegionByTown"
ConvertMethod="ConvertTown"
@bind-Value="RegionReport.RegionName">
<SelectedTemplate Context="region">@region.RegionName</SelectedTemplate>
<ResultTemplate Context="town">@town.Name</ResultTemplate>
</BlazoredTypeahead>
<ValidationMessage For="@(() => RegionReport.RegionName)" />
public class Town
{
[Key]
public string Code { get; set; }
public string Name { get; set; }
}
public class RegionReport
{
[Required]
public string RegionName { get; set; }
}
protected async Task<string> ConvertTown(Town town)
{
RegionReport.RegionName = town?.Name;
return await Task.FromResult(town?.Name);
}
protected async Task<IEnumerable<Town>> GetRegionByTown(string townName)
{
return await RegionService.GetRegionByTown(townName);
}
请问这段代码有什么问题?
解决方案
<BlazoredTypeahead SearchMethod="GetRegionByTown"
ConvertMethod="ConvertTown"
@bind-Value="RegionReport.RegionName">
<SelectedTemplate Context="region">@region</SelectedTemplate>
<ResultTemplate Context="town">@town.Name</ResultTemplate>
</BlazoredTypeahead>
<ValidationMessage For="@(() => RegionReport.RegionName)" />
public class Town
{
[Key]
public string Code { get; set; }
public string Name { get; set; }
}
public class RegionReport
{
[Required]
public string RegionName { get; set; }
}
protected string ConvertTown(Town town)
{
return town?.Name;
}
protected async Task<IEnumerable<Town>> GetRegionByTown(string townName)
{
return await RegionService.GetRegionByTown(townName);
}
解决方案
推荐阅读
- excel - 使用宏对不同工作表进行列标题验证
- java - JLabel 没有更新?
- html - 如何知道使用绝对定位垂直居中需要多少像素?
- reactjs - React-JS / react-router-dom 中的路由问题
- ruby-on-rails - Rails 5 以一种形式创建同一模型的多个记录,未知属性错误
- css - 如何在 IE 11 中显示:grid div 以占据整个屏幕?(100vh 似乎不起作用)
- html - 为什么我的 HTML 表格不遵守指定的布局?
- web-traffic - 如何在给定时间获得给定网址(不在我的网站上)的多次点击?
- javascript - 如何从 3rd 方 api 中提取数据并使用 javascript 将其显示在我的页面上?
- javascript - 反应将增量数据传递给父级