【发布时间】:2017-08-10 19:23:49
【问题描述】:
我知道有人询问并回答了这个问题的变体。但是,这是一个特定情况,其中我定义了 Functions.cshtml 页面,并且我已成功引用了该页面上的函数。我已经能够成功运行我的网站。但是,当我在 IDE 中回忆项目时,VS 2015 会定期找不到 Functions.xyz 引用。有时,我可以将 Functions.cshtml 页面复制到另一个位置,然后将其从项目中删除,关闭 VS,重新打开 VS 并将 Functions.cshtml 重新添加回项目。这本身并不会导致 VS 现在解决问题。然后我必须在 IDE 编辑器中打开 Functions.cshtml 并选择构建网站。然后有时,VS 会解析引用。但是,我现在被困住了 - VS 完全无法解决参考问题,需要关于如何解决它的新想法。以下是代码示例: Functions.cshtml:
@Functions {
public static System.Data.DataSet qryGeneralExecute(string query)
{
using (SqlConnection cn = new SqlConnection(getConnectionString(false).ConnectionString))
using (SqlCommand cmd = new SqlCommand(query, cn))
{
SqlDataAdapter adapter;
System.Data.DataSet ds = new System.Data.DataSet();
cmd.CommandType = System.Data.CommandType.Text;
cn.Open();
adapter = new SqlDataAdapter(cmd);
adapter.SelectCommand = cmd;
adapter.Fill(ds);
cn.Close();
if (ds.Tables.Count > 0)
{
return ds;
}
return null;
}
}
}
调用页面:
{
bor_studinfoDataSet = Functions.qryGeneralExecute(query);
}
当我运行项目时,我得到The name 'Functions' does not exist in the current context。
有解决这个问题的建议吗?
【问题讨论】:
-
在 Razor 中,
@functions不是带有小写的f吗?
标签: c# razor visual-studio-2015