剃刀页面给我 "The type or namespace name 'IBrowserFile' could not be found (are you missing a using directive or an assembly reference?)"

Razor page giving me "The type or namespace name 'IBrowserFile' could not be found (are you missing a using directive or an assembly reference?)"

我一直在关注 https://docs.microsoft.com/en-us/aspnet/core/blazor/file-uploads?view=aspnetcore-5.0 上的“ASP.NET Core Blazor 文件上传”的 MS 文档。

我插入了以下代码

按照步骤,我最终运行在这一行出错

private Dictionary<IBrowserFile, string> loadedFiles = new Dictionary<IBrowserFile, string>();

并得到错误信息

The type or namespace name 'IBrowserFile' could not be found (are you missing a using directive or an assembly reference?)

我得到与 InputFileChangeEventArgs 相同的错误。

我想知道为什么会发生这种情况以及如何解决它。

此功能仅在.net5.0中可用,您可以检查您的框架版本。

我非常推荐升级。这有点棘手,尤其是如果您想使用 CSS 本地化,但今年 Blazor 的变化如此之多,值得付出努力。