Closed nssidhu closed 4 years ago
As the message states, you need to provide a convert method as, I'm assuming, your binding a string value in your form _editprofileModel.CountryName
but you're providing a list of CountryCodes
. You need to tell the Typeahead how to map whatever the value is in your form to a country code.
If you have a look in the readme there is an explanation there.
Today I stumbled over the same problem and the readme doesn't help me, I think due to my lack of expertise with blazor... I don't really understand what exactly to do here...
"you can achieve this by providing a convertMethod" .... but where exactly do i provide this method? As a beginner, I would assume something like this:
<SelectedTemplate @onselect="@(() => Convert(@context))">
@context
</SelectedTemplate>
@Kurti123 If you look at the sample projects there is an example of how to use the convert method:
https://github.com/Blazored/Typeahead/blob/main/samples/BlazorWebAssembly/Pages/Index.razor
I appreciate the readme isn't the best on this topic. I've raised an issue to update it - #185.
Ah I could figure it out with the examples. Thank you!
Hi @chrissainty. may you please add some ccomment on your code.
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Blazored.Typeahead.BlazoredTypeahead:0
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2e5b380 + 0x00030> in :0
2[DbModels.CountryCodes,System.String] requires a ConvertMethod parameter. System.InvalidOperationException: Blazored.Typeahead.BlazoredTypeahead
2[DbModels.CountryCodes,System.String] requires a ConvertMethod parameter. at Blazored.Typeahead.BlazoredTypeahead`2[TItem,TValue].OnInitialized () <0x382bcb0 + 0x00060> inThis is EF generated Class DbModel Class
Editprofile.razor
WebAPI method
[HttpGet] [HttpOptions] [AllowAnonymous] [Produces("application/json")] public async Task GetListOfCountries(string searchCountriesText)
{
if (string.IsNullOrEmpty(searchCountriesText))
{
return BadRequest(new { message = "Missing required parameter (searchCountriesText) ", currentDate = DateTime.Now });
}