error CS1503 cannot convert from 'method group' to 'EventCallback' in blazor

Viewed 351
<div>
    <InputeFile class="form-control" @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?

1 Answers

You are using wrong Event callback, it should be

OnChange

instead of

@onchange

so your code should look like this

<div>
    <InputFile class="form-control" OnChange="@(async e=>await SelectBanner(e))"></InputFile>
</div>

@code {
    protected string banner;

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