C# ASP.NET MVC: Single-Line If Clause in View?

asp.net-mvc, c#

Solution

Try:

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

or

<% if(!Model.DisplayText) Response.Write(Model.MyText); %>

Problem

I got a trivial issue.. and can't solve it. I have this in my view: ` ``` <% if (!Model.DisplayText) { %> <%= Model.MyText %> <% } %> ``` ` As you can see, i am using 3x <% and %>. That just screams like bad code. But I can't seem to get this working in a single line. This throws all kinds of weird errors (such as semicolon missing, and when I add one it throws something else): ` ``` <% if (!Model.DisplayText) { Model.MyText } %> ``` ` Any idea?!

Original source