使用剃刀有条件地在html元素上设置样式始终会编码'字符,并呈现为'。(这会产生错误的html,这意味着浏览器不会呈现所应用的样式。
我尝试了以下方法:
<tr ID="Question-Answer-@(item.QuestionID)" @(!firstItem ? Html.Raw("style=\'display: none\'").ToString() : "" )>
<tr ID="Question-Answer-@(item.QuestionID)" @(!firstItem ? HttpUtility.HtmlDecode("style=\'display: none\'") : "" )>
<tr ID="Question-Answer-@(item.QuestionID)" @(!firstItem ? "style=\'display: none\'" : "" )>
<tr ID="Question-Answer-@(item.QuestionID)" @(!firstItem ? "style='display: none'" : "")>
<tr ID="Question-Answer-@(item.QuestionID)" @(!firstItem ? new HtmlString("style=\'display: none\'").ToString() : "" )>
这两个代码示例均产生以下内容:
<tr ID="Question-Answer-2" style='display: none'>
and I need:
<tr ID="Question-Answer-2" style='display: none'>
这是我的问题的答案:
<tr ID="Question-Answer-@(item.QuestionID)" @{if (!firstItem) { <text> style='display: none' </text> } }>
(nb。我仍然不明白为什么我在上面尝试的5种不同的方法不起作用)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句