Reputation: 451
I want something like the below, if my application is being build under release mode, then my min js file needs to be referred in the view(.cshtml) but if the same application has been rendered in the debug mode, then the raw js file needs to be called. Can you suggest the piece of code which i need to write in my view(.cshtml)?
Upvotes: 0
Views: 58
Reputation: 451
I have referred the below Razor view engine, how to enter preprocessor(#if debug)
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>
Upvotes: 0
Reputation: 2848
Create html helper
public static bool IsReleaseBuild(this HtmlHelper helper)
{
#if DEBUG
return false;
#else
return true;
#endif
}
in view do
@{#if (DEBUG)
<script type="text/javascript" src="file1.js"></script>
#else
<script type="text/javascript" src="file1.min.js"></script>
#endif
}
Upvotes: 1