代码之家  ›  专栏  ›  技术社区  ›  majkinetor

ASP.NET MVC:可选的呈现元素属性

  •  0
  • majkinetor  · 技术社区  · 16 年前

    我知道有一些语法和?可以选择渲染属性。 但我现在找不到它,我需要它…

    比如:

     < input checked=<%? model.IsActivated % >  ...
    

    谢谢。

    因为似乎没人知道…也许是某种不同的视图引擎。 感谢您的回答:)

    1 回复  |  直到 16 年前
        1
  •  1
  •   Dave Archer    16 年前
     <input checked="<%= model.IsActivated ? "checked" : string.empty % >"...
    

    但是“checked”属性的存在可能会导致它被检查,我不记得了。但如果是这样的话,你会想要

    <input <%= model.IsActivated ? "checked=\"checked\"" : string.Empty %> ...
    

    编辑:btw its called the ternary(? or conditional) operator