Reputation: 11
It is my understanding that under the Project->Properties->Build settings there is a 'Define DEBUG constant'. By default the "Debug" configuration has this option checked, which means that '#if DEBUG' should evaluate to try. Also by default the "Release" configuration has this option not checked.
I am programming under vs2010 sp1 in a MVC 3 application and the following is what i have done:
@{
#if DEBUG
<script language="javascript" type="text/javascript">
$(document).ready(function () {
// put all your jQuery goodness in here.
alert('Debug Build');
});
</script>
#else
<script language="javascript" type="text/javascript">
$(document).ready(function () {
// put all your jQuery goodness in here.
alert('Release Build');
});
</script>
#endif }
My problem is that regardless of the build type, Release or Debug, i am getting the alert for 'Debug Build'.
What am i doing wrong?
Upvotes: 1
Views: 896
Reputation: 1265
@{
if(System.Diagnostics.Debugger.IsAttached)
{
<script type="text/javascript">
</script>
}
}
Will work, but isn't optimized like #DEBUG
and will be hit even if being debuged outside VS
Upvotes: 2
Reputation: 2801
That will never work unfortunately. You will need to put something in the viewbag that you set from your controller.
Upvotes: 1