C# and ASP.NET MVC: Using #if directive in a view
I recently discovered that you can simply test:
HttpContext.Current.IsDebuggingEnabled
in Views, which saves you checking symbols in other parts of your app.
A better, more generic solution is to use an extension method, so all views have access to it:
public static bool IsReleaseBuild(this HtmlHelper helper)
{
#if DEBUG
return false;
#else
return true;
#endif
}
You can then use it like follows in any view (razor syntax):
@if(Html.IsReleaseBuild())
...