【发布时间】:2021-09-12 18:23:35
【问题描述】:
我的代码(enclosed in @for loop) 中有多行<th> 和<td> 标记,我想有条件地显示它们。其中一个<th> 标签如下所示:
@for (int j = 0; j < Model.Children.Count; j++)
{
if (Model.Children[j].isCollapsible == true || Model.Children[j].IsCompany == true)
{
<th class="..." style="width: 180px;">
@Html.LabelForModel(Model.Children[j].Title)
@if (Model.Children[j].isCollapsible == true && Model.Children[j].IsCompany == false)
{
// lines of code
}
</th>
}
}
虽然这工作得很好,但是为了使代码更紧凑,我想用<th>标签的条件style=display:none属性替换上面代码sn-p中的外部if
我试过style="width: 180px; display: "@(Model.Children[j].isCollapsible == true || Model.Children[j].IsCompany == true)" ? none : table-cell",但它显示错误:
谁能告诉我我在这里做错了什么?
【问题讨论】:
标签: c# html css asp.net-mvc razor