Blazor InputFile onchange doesn’t trigger the method

@page "/fileup"
<h3>FileUp</h3>
<InputFile OnChange="@UploadedExcel" accept=".xlsx" />
@code {
    public async Task UploadedExcel(InputFileChangeEventArgs e)
    {
        Console.WriteLine("Hello");
        
    }
}

The code should be basic enough but it doesn’t trigger the task down below when I upload a file. Am I missing something?

I have tried a few different things including changing to multifile and all. I have another page with full code block that I don’t wanna sahre because of many unrelated things. But this on itself should work right?
Network

I was missing the @rendermode InteractiveAuto at the top of the page. After adding it, it triggered my method.

It does work, however there seems to be a misunderstanding on your end.

I am assuming that you think the code does not get executed because you don’t see a Hello printed in your console, when you run the app with dotnet run or dotnet watch or within your preferred IDE. And yes, nothing will be printed there, but that’s absolutely expected.

If you have a Blazor WebAssembly app the UploadedExcel() method is going to run on the client-side in the browser, which means the Console.WriteLine("Hello") will print to the browser console, not the console/ terminal on the server side.

Check your browser console (Open Developer tools -> Choose Tab Console) and you will see Hello getting printed.

Leave a Comment