tags:

views:

314

answers:

3
+11  A: 

Try:

<%= Model.DisplayText ? "" : Model.MyText %>

or

<% if(!Model.DisplayText) Response.Write(Model.MyText); %>
RedFilter
Beaten to the punch, nice post.
Odd
The ternary operator solution was exactly what I needed. Thank you! P.S. In that case there wouldn't be a semicolon so you may want to remove that for others that look up this solution. Thanks again!
Alex
@Alex -- fixed.
tvanfosson
Thanks :) .
RedFilter
+1  A: 

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.

Pavel Minaev
You're missing a semi-colon after the call to Response.Write at the least, and this is probably a case where the brackets would best be left out.
kastermester
+1  A: 

<%= %> 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.

Odd
All answers were great :) Thank you!
Alex