Home > Software design >  error CS1503 cannot convert from 'method group' to 'EventCallback' in blazor
error CS1503 cannot convert from 'method group' to 'EventCallback' in blazor

Time:02-01

<div>
    <InputeFile  @onchange="SelectBanner"></InputFile>
</div>

I want to get full path of file from input in blazor page
but I have this error:
cannot convert from 'method group' to 'EventCallback' in blazor

and this is my method that should get full path of selected file:

@code {
           protected string banner;

           protected async Task SelectBanner(InputFileChangeEventArgs e)
           {
               banner = e.File.Name;
           }
      }

how can I fix this error?

CodePudding user response:

You are using wrong Event callback, it should be

OnChange

instead of

@onchange

so your code should look like this

<div>
    <InputFile  OnChange="@(async e=>await SelectBanner(e))"></InputFile>
</div>

@code {
    protected string banner;

    protected async Task SelectBanner(InputFileChangeEventArgs e)
    {
        banner = e.File.Name;
    }
}
  •  Tags:  
  • Related