I have a partial view that includes only basic HTML, no razor code or model. I use this to set up some "guides" for page layout.
What would be the proper/simplest way to only include this partial when the site is run in debug mode?
I know that in my compiled code I could use directives in my C# code to include sections. Is there something similar in razor?
You can use HttpContext.Current.IsDebuggingEnabled
which would check web.config
s' debug setting:
@if(HttpContext.Current.IsDebuggingEnabled) {
//Do something here.
}
OR use an extension helper method:
public static Boolean DEBUG(this System.Web.Mvc.WebViewPage page) {
// use this sequence of returns to make the snippet ReSharper friendly.
#if DEBUG
return true;
#else
return false;
#endif
}
and usage:
@if(DEBUG()) {
//debug code here
} else {
//release code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With