【发布时间】:2014-09-16 22:47:44
【问题描述】:
我看过这个相关的问题Creating and Simple Class and Calling a Method from a cshtml File。我们如何在不使用 App_Code 文件夹的情况下做到这一点?
在我的项目的根目录中,我有一个 Something.cs 类:
public class Something
{
public static void DoIt()
{
}
}
在我的项目的根目录中,我还有 index.cshtml 和以下代码:
@Something.DoIt()
名称Something 在 index.cshtml 的当前上下文中不存在。
【问题讨论】:
-
@Something.DoIt()表示你正在渲染一些东西,所以DoIt()方法应该有返回值。顺便问一下,Something 课你在哪里上课?