我无法让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引擎将其显示为文字字符串,而不是渲染我的资源文件中的值。
答案 0 :(得分: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 })
答案 1 :(得分: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>