2012-07-24 61 views
0

我剛更改了一些代碼,將我數據庫中所有葡萄酒的全部計數添加到視圖模型中。當我複製所有更新的文件到我的服務器,我不斷收到以下錯誤:當我更新服務器文件時,MVC3網站未更新

'vf2.ViewModels.MyAccountViewModel' does not contain a definition for 'DBWineCount' and no extension method 'DBWineCount' accepting a first argument of type 'vf2.ViewModels.MyAccountViewModel' could be found (are you missing a using directive or an assembly reference?)

這在我的dev的盒子做工精細,並且該文件是相同的。我編輯我的web.config文件強制編譯,但我仍然有這個問題。如果我嘗試使用ViewBag,它不會拋出錯誤 - 但它返回一個空值。這裏會發生什麼?下面是我的代碼示例:

namespace vf2.ViewModels 
{ 
    public class MyAccountViewModel 
    { 
     public DistributorUser DistributorUser { get; set; } 
     public ProducerUser ProducerUser { get; set; } 
     public RestaurantUser RestaurantUser { get; set; } 
     public UserObj UserObj { get; set; } 

     [Display(Name="Email")] 
     public string MembershipEmail { get; set; } 

     public string GetFullName() 
     { 
      return this.UserObj.FirstName + " " + this.UserObj.LastName; 
     } 

     public string sInstitutionTab { get; set; } 
     public string DBWineCount { get; set; } 

    } 
} 

[Authorize] 
     public ActionResult MyAccount() 
     { 
      MyAccountViewModel myAccount = new MyAccountViewModel(); 
      MembershipUser muCurrent = Membership.GetUser(true); 
      muCurrent = Membership.GetUser(true); 

      myAccount.UserObj = db.UserObjs.Find(muCurrent.ProviderUserKey); 
      myAccount.MembershipEmail = muCurrent.Email; 
      int iDocCount = 0; 
      int iRevCount = 0; 

      if (myAccount.UserObj != null) 
      { 
       myAccount.DBWineCount = string.Format("{0:n0}",db.Wines.Count()); 

       switch ((UserTypesEnum)myAccount.UserObj.UserTypeID) 
       { 
        case UserTypesEnum.Producer: 
         myAccount.ProducerUser = db.ProducerUsers.Find(muCurrent.ProviderUserKey); 
         myAccount.sInstitutionTab = "My Producer"; 
         myAccount.ProducerUser.Producer.Wines.ToList().ForEach(w => iDocCount += w.Docs.Count); 
         myAccount.ProducerUser.Producer.Wines.ToList().ForEach(w => iRevCount += w.Reviews.Count); 
<I cut the rest out because it is pretty long> 


<div class="lightbox" id="gettingStarted" style="text-align:center;"> 
    <a href="#" class="ui-icon ui-icon-circle-close closer"></a> 
    <h3 style="margin-top:0px;">Getting Started</h3> 
    <br /> 
    To get started using the site, search useing the searchbox above or the search 
    tab on the left. 
    <br />From there you'll have access to all @Model.DBWineCount wines in our database. 
     <br /> 


</div> 
+0

你正在複製編譯的文件嗎? – ryudice 2012-07-24 02:14:40

+0

嗯,我只是從我的開發機器直接複製我的項目文件。編譯的文件是.dll還是其他的? – user576838 2012-07-24 02:40:12

+0

在複製文件之前,您正在編譯項目嗎? – ryudice 2012-07-24 02:48:21

回答

1

我懷疑你是來自ASP.NET開發,編譯器在第一次訪問頁面時自動運行。 在ASP.NET MVC中,您需要使用Visual Studio的發佈命令強制編譯。右鍵單擊解決方案並選擇「發佈...」,然後選擇您想要發佈文件的文件夾,然後將該文件夾的內容上傳到生產服務器。

請注意,如果您使用實體框架並在共享主機上,您可能沒有權限運行該應用程序並讓EF自動爲您創建數據庫。在這種情況下,您將需要生成SQL腳本並在數據庫上手動執行這些腳本。

請注意,修改web.config只會重新啓動應用程序,但不會執行任何編譯。在ASP.NET MVC中,您將需要顯式構建一個項目以在測試時進行編譯。

+0

讓我確認你的懷疑!太好了,我會按照你的指示 - 謝謝你! – user576838 2012-07-24 11:53:01