如果值恰好为负值,如何有条件地将样式'color:red'添加到.CurrentDifference?
谢谢, 杆
<div class="sRow">
<div class="sLabel p40">
Difference:
</div>
<%= (!String.IsNullOrEmpty(Model.Amount)?Model.Amount.CurrentDifference.ToString("c"):string.Empty) %>
</div>
答案 0 :(得分:1)
我会在你的样式表中为红色添加一个类。然后有条件地将类应用于跨度。
<div class="sRow">
<div class="sLabel p40">
Difference:
</div>
<span class='<%= (Model.Amount>0?"Currency":"CurrencyRed") %>' >
<%= (!String.IsNullOrEmpty(Model.Amount)?Model.Amount.CurrentDifference.ToString("c"):string.Empty) %>
</span>
</div>
答案 1 :(得分:1)
<div class="sRow">
<div class="sLabel p40">
Difference:
</div>
<span style="<%=Model.Amount.CurrentDifference < 0 ? "color: #FF0000": ""%>">
<%= (!String.IsNullOrEmpty(Model.Amount)?Model.Amount.CurrentDifference.ToString("c"):string.Empty) %>
</span>
</div>
请注意,这非常草率。我会考虑在Controller Action中加入逻辑,而不是在View中放置条件逻辑。也许使用tempdata甚至在模型中公开一个新字段。