我刚开始玩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版本有关,或者也许我需要安装一个软件包。
IJSObjectReference
仅在.NET 5中可用。因此,使用.NET 5创建项目解决了该问题。