Reputation: 331
As I understand it, with .NET 5 in Blazor I should be able to use InputFile. I don't have that option. I am on VS 16.8, I have the .net 5 SDK installed, in a Blazor Web Assembly project (using .Net Standard 2.1), with .Net Core Hosted (using .Net 5) but InputFile is not recognized as valid syntax. Am I missing something really obvious?
Upvotes: 1
Views: 2129
Reputation: 73
i think it should just "work" in a .razor file (assuming you are targetting net5.0
). i'm using it in a Blazor Server app without any extra using
statements. it's part of the Microsoft.AspNetCore.Components.Forms namespace
@page "/"
@using server.Data //this is specific to my app
@using server.Data.Util //this too
@inject IJSRuntime js //this is just the js interop
...
<InputFile OnChange="@HandleFileSelectedAsync" />
<section>
@if (_uploading)
{
<p>Uploading...</p>
<div class="loader"></div>
}
...
UPDATE: i also noticed i had a _Imports.razor
file in my project that must have gotten created by VisualStudio when i made a new project. it looks like this:
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms //InputFile in here
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
...
Upvotes: 0
Reputation: 3
After the suggestion by Mario that the Blazor app should be targeting .net 5.0, I went to the project properties and found that it was targeting .net core 3.1 by default.
Changing the target to .net 5.0 made it work.
Thank you!
Upvotes: 0
Reputation: 106
The templates for visual studio havent been updated so its still targets .NET standard rather than .NET 5. Use this guide https://www.davideguida.com/how-to-migrate-blazor-webassembly-to-net-5/
Upvotes: 1