C# and ASP.NET MVC: Using #if directive in a view

前端 未结 7 2156
不知归路
不知归路 2020-12-03 04:05

I\'ve got a conditional compilation symbol I\'m using called \"RELEASE\", that I indicated in my project\'s properties in Visual Studio. I want some particular CSS to be app

7条回答
  •  长情又很酷
    2020-12-03 04:49

    You can use ViewBag instead of viewmodel (but viewmodel-like approach is better) :

    Controller :

    controller code

    View :

    @{
       bool hideYoutubeVideos = ViewBag.hideYoutubeVideos ?? false;     
    }
    

    Usage :

    @if (!hideYoutubeVideos)
    {
         hello youtube
    }
    

    Also, be sure, that NIKITA_DEBUG variable exist in build tab of your project :

    build tab

提交回复
热议问题