Try:
<%= Model.DisplayText ? "" : Model.MyText %>
or
<% if(!Model.DisplayText) Response.Write(Model.MyText); %>
RedFilter
2009-07-22 23:42:37
Try:
<%= Model.DisplayText ? "" : Model.MyText %>
or
<% if(!Model.DisplayText) Response.Write(Model.MyText); %>
This:
<%= foo %>
is generally equivalent to:
<% Response.Write(foo) %>
So you can write:
<% if (!Model.DisplayText) { Response.Write(Model.MyText); } %>
but I don't see what you really get from this. Your original code is fine as it is. Or you might use the ternary operator, as OrbMan suggests.
<%= %> is basically like writing Response.Write(your data)
<% %> means the code will execute, but it's not going to specifically write anything out.
You could use a Response.Write inside your if block to output the data you want.
<% if (!Model.DisplayText) { Response.Write(Model.MyText); } %>
Or go with OrbMan's answer, he beat me to it.