Debug directive inside the view

Preprocessor directive #if DEBUG allows us to check whether the application is compilled in debug mode or release. It is so easy that we do not suspect any problems. The following code should work always and everywhere:

    string stateBuild;
    #if DEBUG
        stateBuild = "Debug";
        stateBuild = "Release";

When we use it in MVC View then it doesn't matter how we build our application, the #if DEBUG condition always will be true.

The Reason:

We have to know that the web application is compiled every time when someone want to display our page. This automatic compilation made by ASP.NET engine is always made in debug mode.

The Solution:

The best solution is to define a static property in helper class or into controller. Here is whole code:

    public static bool IsDebug
        get { 
                #if (DEBUG)
                    return true;
                    return false;