c# - ? Operator using MVC Razor syntax -
<span>@model.selectedordertypename @model.percentage ? @model.financialsupportpercentage % : @model.amount $</span>
how do above in razor syntax? (basically if percentage not null display otherwise display amount
you need use brackets
<span>@model.selectedordertypename @(model.percentage != null ? model.financialsupportpercentage + "%" : model.amount + "$")</span>
without brackets, every time use @
returning something, meaning displaying <span>
containing @model.selectedordertypename
's value, @model.percentage
's, value ?
literal character, @model.financialsupportpercentage
's value, %
literal character, :
, @model.amount
's value , $
literal.
adding brackets turns 1 return - allowing ternary functions written.
Comments
Post a Comment