使用剃须刀在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件事不起作用(