0

我无法让 Razor 引擎处理下一行中的 data_content 属性。它将 @String.Format 部分视为文字字符串而不是 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 引擎不会呈现我的资源文件中的值,而是将其显示为文字字符串。

在此处输入图像描述

4

2 回答 2

1

因为您已经处于“代码”模式,所以您不需要@before 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 })
于 2013-03-02T16:15:23.840 回答
0

看来这个片段有效。

我错误地假设 Resources.Resource.VisitPurpose 变量需要用引号括起来。这就是为什么我最初在那里有 String.Format 的原因。

我删除了这些引号并呈现了页面。然后,我查看了页面源代码,并低调地看到了 Razor 引擎为我放入了它们。

感谢大家的关注和耐心。

<div class="control-group">
        @Html.LabelFor(model => model.VisitPurpose, @UrgentCareWaitWeb.Resources.Resource.VisitPurpose, new { @class = "control-label" })
        <div class="controls">
            @Html.TextArea("VisitPurpose", null, new { @data_toggle = "hover", @class = "hasPopover input-xxlarge", rows="6", data_placement = "right", data_content =  Resources.Resource.VisitPurpose   })
        </div>
    </div>
于 2013-03-04T17:19:18.667 回答