I have a problem with Typeahead with my Blazor-Server app:
<BlazoredTypeahead style="width: auto" SearchMethod="SearchUser"
@bind-Value="calc.FkCustomerId">
<SelectedTemplate>
@context.AccountCode
</SelectedTemplate>
<ResultTemplate>
@context.CustomerSname (@context.AccountCode)
</ResultTemplate>
</BlazoredTypeahead>
@{
private async Task<IEnumerable<AutolineAccts>> SearchUser(string SelectedUser)
{
return await Task.FromResult(alContext.AutolineAccts.Where(x => x.CustomerSname.Contains(SelectedUser)).ToList());
}
}
The problem I have occurs in the SelectedTemplate part:
'string' does not contain a definition for 'AccountCode' and no accessible extension method 'AccountCode' accepting a first argument of type 'string' could be found
Intellisense is supposed to show me all the fields of AutolineAccts, but it does not. But it works for the @context object within the node
'string' does not contain a definition for 'AccountCode' and no accessible extension method 'AccountCode' accepting a first argument of type 'string' could be found
The conext
in <SelectedTemplate>
is corresponding to that in @bind-Value
, seems that calc.FkCustomerId
is a string type value, and it definetely doesn't have a AccountCode
property, so the above error occurs.
You can refer to this article for how to use Blazored Typeahead.