Razor syntax to render section based on condition

后端 未结 2 1651
难免孤独
难免孤独 2020-12-29 23:38

I got a view with Layout defined. In the layout, there is a section:

@RenderSection(\"JavaScript\", required: false)

In the view, based on a c

2条回答
  •  悲&欢浪女
    2020-12-30 00:15

    @if(condition) RenderSection(..)

    @Section Javascript{ 
            
    } 
    } 

    also see: Is there a way to make a @section optional with the asp.net mvc Razor ViewEngine?

提交回复
热议问题