Is it possible to make Razor sections optional?

后端 未结 5 1345
悲哀的现实
悲哀的现实 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:26

    You can set a section to be optional by setting the required parameter to false. If you'd like to include some optional wrapper HTML around your section then you can also use the IsSectionDefined method.

    @if(IsSectionDefined("SideBar"))
    {
        
    }
    

提交回复
热议问题