---
title: "How to use  #if directive in a view in mvc?"  
description: "How to use  #if directive in a view in mvc?"  
author: "Anonymous User"  
published: 2014-10-17  
updated: 2014-10-17  
canonical: https://www.mindstick.com/forum/2405/how-to-use-if-directive-in-a-view-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc", "mvc", "view"]  
reading_time: 2 minutes  

---

# How to use  #if directive in a view in mvc?

I've got a conditional [compilation](https://www.mindstick.com/interview/358/which-is-the-first-level-of-compilation-in-the-dot-net-languages) symbol I'm using called "RELEASE", that I indicated in my [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects)'s [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) in [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available). I want some particular CSS to be applied to [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-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](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-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](https://www.mindstick.com/articles/157223/5-inbound-project-management-insights-every-client-needs-to-know) into this? Any help would be appreciated. Thanks.\
[Clarification](https://www.mindstick.com/forum/1682/regex-ismatch-clarification-using-c-sharp): I should have mentioned that this view is already a [partial view](https://www.mindstick.com/articles/1132/auto-refresh-partial-view-in-asp-dot-net-mvc), and I'll simply render it in pages where I need it. That's because these banners will be on certain pages and not others. So even when rendering it as a partial view via:\
[Html.RenderPartial](https://www.mindstick.com/forum/2318/what-is-the-difference-between-html-partial-and-html-renderpartial-and-html-action-and-html-renderaction)("BannerView");\
it's not working.

## Replies

### Reply by Anonymous User

You can use this for access all views

```
public static bool IsReleaseBuild(this HtmlHelper helper){     #if DEBUG             return false;     #else             return true;     #endif }
```

### Reply by Anonymous User

In your model:\

```
bool isRelease = false;<% #if (RELEASE) %>    isRelease = true;<% #endif %>
```

In your view:\

```
<% if (Model.isRelease) { %>    <div class="releaseBanner">Banner text here</div><% } else { %>    <div class="debugBanner">Banner text here</div><% } %>
```


---

Original Source: https://www.mindstick.com/forum/2405/how-to-use-if-directive-in-a-view-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
