0

情况如下:

假设我在 App_Code 中有两个文件,每个文件都包含函数块:

这是文件 AppCode/File1.cshtml 中的示例函数 #1:

@functions {
  public static Boolean getTrue() {
    return true;
  }
}

这是文件 AppCode/File2.cshtml 中的示例函数 #2:

@functions {
  public static Boolean getFalse() {
    return false;
  }
}

我可以通过@File1.getTrue() 或@File2.getFalse() 从我的根文件夹中引用CSHTML 文件中的任一函数。

但是,我可以在 AppCode/File1.cshtml 中调用 @File2.getFalse() 以便:

@functions {
   public static Boolean getTrue() {
     return (!@File2.getFalse());
   }
}
4

1 回答 1

1

helper用关键字标记的函数中的代码是纯 C#。因此,您应该删除 Razor @ 符号。这应该只用于将服务器端变量和表达式结果呈现给浏览器。

 @functions {
   public static Boolean getTrue() {
     return (!File2.getFalse());
   }
}
于 2013-08-14T05:57:49.150 回答