【发布时间】:2021-12-07 08:50:40
【问题描述】:
@(item.ID == 0 ? "" : <i class="fas fa-bus"></i>)
当我尝试上述语句时,Razor 不喜欢它,它看起来像是有效的 C# 代码。 如果 ID 为 0,我需要做些什么来包装我的 html 标签,以便在我的 UI 中呈现它?
【问题讨论】:
标签: asp.net-core razor conditional-operator
@(item.ID == 0 ? "" : <i class="fas fa-bus"></i>)
当我尝试上述语句时,Razor 不喜欢它,它看起来像是有效的 C# 代码。 如果 ID 为 0,我需要做些什么来包装我的 html 标签,以便在我的 UI 中呈现它?
【问题讨论】:
标签: asp.net-core razor conditional-operator
尝试使用:
@if (item.ID != 0)
{
<i class='fas fa-bus'></i>
}
【讨论】: