How to render scripts, generated in TagHelper process method, to the bottom of the page rather than next to the tag element?

后端 未结 7 1426
情深已故
情深已故 2020-12-11 06:28

I am generating scripts in process method of TagHelper class as follows

[TargetElement(\"MyTag\")]
    public Class MYClass: TagHelper{
      public override         


        
7条回答
  •  青春惊慌失措
    2020-12-11 07:22

    Have a @section scripts {} that's rendered on Layout with @RenderSection("scripts") and place your tag helper inside the a scripts section. When rendered, It will be placed where is defined on Layout (at the bottom of your html).

    
    
    
    
    
        

    some html ... bla bla bla

    @RenderBody()
    @RenderSection("scripts", required: false)

    then on any other cshtml file,

    Some page

    @section scripts { foo }

提交回复
热议问题