C# and ASP.NET MVC: Using #if directive in a view

Posted by Mega Matt on Stack Overflow See other posts from Stack Overflow or by Mega Matt
Published on 2010-06-01T15:40:18Z Indexed on 2010/06/01 15:43 UTC
Read the original article Hit count: 142

Hi all,

I've got a conditional compilation symbol I'm using called "RELEASE", that I indicated in my project's properties in Visual Studio. I want some particular CSS to be applied to elements when the RELEASE symbol is defined, and I was trying to do that from the view, but it doesn't seem to be working.

My view code looks like this (shortened a bit for demo purposes):

<% #if (RELEASE) %>
    <div class="releaseBanner">Banner text here</div>
<% #else %>
    <div class="debugBanner">Banner text here</div>
<% #endif %>

With this code, and with the RELEASE symbol set, the 'else' code is running and I'm getting a div with the debugBanner class. So it doesn't seem to think that RELEASE is defined. It's worth noting that my actual C# code in .cs files is recognizing RELEASE and runs the correct code. It's only the view that is giving me the problem.

Does anyone have any insight into this? Any help would be appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc