【问题标题】:Inserting HTML into Razor view based on conditional value根据条件值将 HTML 插入 Razor 视图
【发布时间】: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


    【解决方案1】:

    尝试使用:

    @if (item.ID != 0)
    {
        <i class='fas fa-bus'></i>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2015-09-27
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      相关资源
      最近更新 更多