2015-01-02 10 views
0

我有下面的代碼,它工作正常。假設我現在想改變ActionLinkButton方法中的某些內容,例如爲其簽名添加另一個 參數。當然,我也必須改變.cshtml中的調用。但是,如果我不更改 .cshtml,則應用程序僅在嘗試顯示View時崩潰,並且定向到默認錯誤的html頁面,所以沒有編譯錯誤。日誌中沒有錯誤的詳細信息螢火蟲,任何地方。 顯然,當我做出這樣的改變時,我應該儘量記得檢查所有的電話,但我忘記了。
那麼,我該如何防止這個錯誤或使其更易於追蹤?
1.某種形式的Razor語法檢查器?
2.通過一些有意義的消息引導到錯誤頁面的一些方法?預防或剃刀錯誤的詳細信息

的.cs

public static MvcHtmlString ActionLinkButton(
     this HtmlHelper htmlHelper, 
     string buttonText, 
     string actionName, 
     string controllerName, 
     RouteValueDictionary routeValues, 
     Boolean enable) 
    { 
     string href = UrlHelper.GenerateUrl("default", actionName, controllerName, routeValues, RouteTable.Routes, htmlHelper.ViewContext.RequestContext, false); 
     // title is tooltip 
     string buttonHtml; 
     if (enable) 
     { 
      buttonHtml = string.Format("<input type=\"button\" title=\"Export\" value=\"{0}\" onclick=\"location.href='{1}'\" class=\"button\" />", buttonText, href); 
     } 
     else // disable button 
     { 
      buttonHtml = string.Format("<input type=\"button\" disabled=\"disabled\" title=\"Export\" value=\"{0}\" onclick=\"location.href='{1}'\" class=\"button\" />", buttonText, href); 
     } 
      return new MvcHtmlString(buttonHtml); 
} 

.cshtml

@Html.ActionLinkButton(
      buttonText: "Export", 
      actionName: "Export", 
      controllerName: "Detail", 
      routeValues: new RouteValueDictionary(new {PermitId = @Model.PermitId }), 
      enable : false) 
+0

你有沒有調試你的代碼,驗證方法的參數可能是這裏的錯誤。 –

+1

編輯Web.config文件以關閉customErrors模式。 – Casey

+0

是的,這確實提供了準確的信息。謝謝。我有Web.Debug.config文件設置爲關閉,但這是不夠的。我必須在Web.config中完成。 –

回答

1

您可以編譯生成時你的剃鬚刀的意見,所以你會跑之前得到剃刀編譯錯誤。

Set <MvcBuildViews>true</MvcBuildViews> in the <PropertyGroup> element of your .csproj file.

How to compile cshtml before runtime

可能會很慢,我只在發佈啓用它。

+0

這會導致構建錯誤: 錯誤 在應用程序級別之外使用註冊爲allowDefinition ='MachineToApplication'的節是錯誤的。 此錯誤可能是由於虛擬目錄未被配置爲IIS中的應用程序。 –

+0

修復就像Chris Hynes在這裏所建議的那樣:http://stackoverflow.com/questions/4725387/mvcbuildviews-not-working-correctly –