【问题标题】:Visual Studio - Razor website cannot find C# class fileVisual Studio - Razor 网站找不到 C# 类文件
【发布时间】:2015-11-30 18:44:55
【问题描述】:

我有一个包含一些代码的 C# 文件,我想在我的 Razor HTML 页面中引用它,使用以下代码:

@{
    var check = new pingDevice();
}

//In the main HTML page:

<button onclick="@check.pingDevice().isConnected()">Ping Devices (See Console)</button>

但是,当我尝试这样做时,我收到以下错误:

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

我的 Bin 文件夹中包含 CS 文件,但我仍然遇到同样的错误。

我做错了什么?我应该使用其他方法在我的 Razor 项目中包含代码吗?

【问题讨论】:

  • 您是否将相关的using 指令放在您的html 页面顶部?它看起来像:@using MyNamespace.
  • 我试过了,但我得到了同样的错误,说找不到命名空间名称。

标签: c# asp.net visual-studio razor


【解决方案1】:

这可能会起作用:

<button onclick="@check.isConnected()">Ping Devices (See Console)</button>

check 是一个 pingDevice,它可能没有函数 pingDevice()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多