Razor 中的预处理器指令 [英] Preprocessor directives in Razor
本文介绍了Razor 中的预处理器指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我今天正在写我的第一个 Razor 页面,但不知道如何进入
I am writing my first Razor page today, and can't figure out how to enter
#if debug
...
#else
...
#endif
如何在 Razor 中做到这一点?
How can I do that in Razor?
推荐答案
我刚刚创建了一个扩展方法:
I just created an extension method:
public static bool IsDebug(this HtmlHelper htmlHelper)
{
#if DEBUG
return true;
#else
return false;
#endif
}
然后像这样在我的视图中使用它:
Then used it in my views like so:
<section id="sidebar">
@Html.Partial("_Connect")
@if (!Html.IsDebug())
{
@Html.Partial("_Ads")
}
<hr />
@RenderSection("Sidebar", required: false)
</section>
由于帮助程序是使用 DEBUG/RELEASE 符号编译的,所以它可以工作.
Since the helper is compiled with the DEBUG/RELEASE symbol, it works.
这篇关于Razor 中的预处理器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文