2013-03-02 98 views
0

我無法讓Razor引擎處理下面一行中的data_content屬性。它將@ String.Format部分視爲文字字符串而不是Razor命令。我曾嘗試@:和@ |無濟於事。Razor命令不顯示

@Html.TextArea("VisitPurpose", null, 
    new { 
     @data_toggle = "hover", 
     @class = "hasPopover input-xxlarge", 
     rows="6", 
     data_placement = "right", 
     data_content = "@String.Format({0}, @Resources.Resource.VisitPurpose)" 
    }) 

只是要清楚這不起作用或者:

@Html.TextArea("VisitPurpose", null, 
     new { 
      @data_toggle = "hover", 
      @class = "hasPopover input-xxlarge", 
      rows="6", 
      data_placement = "right", 
      data_content = "@Resources.Resource.VisitPurpose)" 
     }) 

上面的代碼渲染此我的網頁上。 Razor引擎不是渲染我的Resource文件中的值,而是將其顯示爲文字字符串。

enter image description here

+0

請問您可以在我的回答下檢查斯科特 - 帕斯科和我的問題嗎?並請發佈500內部錯誤的內容。順便說一下,我建議使用'data_content = Resources.Resource.VisitPurpose'而不是'data_content =「@Resources.Resource.VisitPurpose)」' – nemesv 2013-03-03 07:18:52

回答

1

因爲你已經在「代碼」模式下,你不需要@String.Format

@Html.TextArea("VisitPurpose", null, 
    new { @data_toggle = "hover", 
      @class = "hasPopover input-xxlarge", 
      rows="6", data_placement = "right", 
      data_content = String.Format("{0}", Resources.Resource.VisitPurpose)}) 

順便說與您當前的代碼(例如僅在"{0}"模式你的字符串格式)你根本不需要String.Format

@Html.TextArea("VisitPurpose", null, 
    new { @data_toggle = "hover", 
      @class = "hasPopover input-xxlarge", 
      rows="6", data_placement = "right", 
      data_content = Resources.Resource.VisitPurpose }) 
+0

感謝您的幫助,但刪除@並不能解決它。這樣做的話頁面會得到500個服務器錯誤。 String.Format只是因爲我認爲這有助於重新提供Resources.Resource.VisitPurpose變量。此標記的全部內容是獲取輸出中包含的Resources.Resource.VisitPurpose變量。 – ChiliYago 2013-03-02 17:39:35

+0

「Resources.Resource.VisitPurpose」的類型是什麼?什麼是錯誤信息? – nemesv 2013-03-02 17:46:47

+0

是的,它是一個Bootstrap popover。資源被使用,因爲它需要顯示西班牙文和英文文本。 – ChiliYago 2013-03-02 17:55:41

0

it appe這個片段的作品。

我錯誤地認爲Resources.Resource.VisitPurpose變量需要用引號包圍。這就是我原來在那裏有String.Format的原因。

我刪除了這些引號和呈現的頁面。然後,我回顧了頁面源代碼,並且低調地看到Razor引擎爲我提供了它們。

感謝大家的關注和耐心。

​​