Is it possible to make Razor sections optional?

后端 未结 5 1342
悲哀的现实
悲哀的现实 2021-01-11 11:45

If I have a page with:


    @section SomeStuff {
        This is a section I just addered
    }


         


        
5条回答
  •  有刺的猬
    2021-01-11 12:31

    I encountered a similar issue when I was trying to dynamically inject code into an inline script, I solved it via:

    @if (someCondition)
        {
            @Html.Raw(@"
                  Your stuff here
            ");
        }
    

提交回复
热议问题