2017-08-10 12 views
-1

我知道已經提出並回答了此問題的各種變體。但是,這是一個特定的情況,我定義了一個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

關於解決此問題的任何建議?

+0

Razor中的'@ functions'是否帶有小寫'f'? – Scott

回答

0

好的,這是發生了什麼事。在我的項目開始工作的時候,現在我開始糾正一個完全不相關的SQL Server管理系統(SSMS)問題,並且無法在嚴格的安全環境下登錄SQL實例。這涉及卸載&多次重新安裝SQL。在糾正此問題的過程中,雖然安裝了v3.5,但SQL Server Compact 4.0已被卸載。很明顯,這不知何故引發了這個問題,包括我認爲是無關的錯誤「無法加載文件或程序集'System.Web.Helpers',版本= 3.0.0.0或其依賴項之一」,但似乎是相關的。我通過微軟的NuGet進行更新,解決了這個助手錯誤.AspNet.WebPages(在這裏找到了Bjorn的解決方案 - Could not load file or assembly 'System.Web.Helpers, error on IIS 8 - 謝謝比約恩)。一旦我糾正這個助手錯誤,此函數錯誤已解決,但我收到錯誤「無法加載文件或程序集system.data.sqlserverce,版本= 4.0.0.0或其依賴項之一」。尋找它的解決方案,我被帶到Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0。從那裏開始,我開始下載並安裝MS SQL Compact v4.0,並且最後一個錯誤消除了。該項目現在編譯,我可以運行我的應用程序。

相關問題