Warm tip: This article is reproduced from serverfault.com, please click

c#-找不到类型或名称空间IJSObjectReference

(c# - The type or namespace IJSObjectReference could not be found)

发布于 2020-11-29 19:52:18

我刚开始玩Blazor。我想从剃刀局部类调用javascript函数。

using Microsoft.JSInterop;
public partial class Counter
{
    [Inject] IJSRuntime js { get; set; }
    IJSObjectReference module;

    [JSInvokable]
    public async Task IncrementCount()
    {
        module = await js.InvokeAsync<IJSObjectReference>("import", "./js/Counter.js");
        await module.InvokeVoidAsync("displayAlert", "New message");
    }
}

我收到以下错误The type or namespace IJSObjectReference could not be found也没有选择将软件包安装在intellisense中,也要假设它是缺少的软件包问题。我已经搜索过但没有看到任何相关信息。我认为此问题与.NET 5版本有关,或者也许我需要安装一个软件包。

Questioner
Qudus
Viewed
0
Qudus 2020-12-09 00:02:17

IJSObjectReference 仅在.NET 5中可用。因此,使用.NET 5创建项目解决了该问题。