【问题标题】:Blazor namespace Interop does not extist in the namespace命名空间中不存在 Blazor 命名空间互操作
【发布时间】:2019-03-01 10:53:18
【问题描述】:
在哪里可以找到程序集引用以及如何添加它?
错误说明:
CS0234 名称空间“Microsoft.AspNetCore.Blazor.Browser”中不存在类型或名称空间名称“Interop”(您是否缺少程序集引用?)
CS0103 当前上下文 Phoneword.Client 中不存在名称“RegisteredFunction”
我有一个小型 Blazor 项目,我想在一段时间后再次运行它。但似乎我已经删除了引用或其他内容已损坏。
编辑我:
Blazor:0.5.1
目标框架:.NET Standart 2.0
【问题讨论】:
标签:
c#
namespaces
interop
assembly-references
blazor
【解决方案1】:
“RegisteredFunction”不再存在。
这是在 JavaScript 文件中定义函数的方式:
window.exampleJsFunctions = {
showPrompt: function (message) {
return prompt(message, 'Type anything here');
}
};
这就是您从 Blazor 代码中调用函数的方式:
using Microsoft.JSInterop;
public class ExampleJsInterop
{
public static Task<string> Prompt(string message)
{
// Implemented in exampleJsInterop.js
return JSRuntime.InvokeAsync<string>(
"exampleJsFunctions.showPrompt",
message);
}
}