how to add script src inside a View when using Layout

前端 未结 3 967
清酒与你
清酒与你 2020-12-04 07:19

I want to include a javascript reference like:


         


        
3条回答
  •  忘掉有多难
    2020-12-04 08:06

    Depending how you want to implement it (if there was a specific location you wanted the scripts) you could implement a @section within your _Layout which would enable you to add additional scripts from the view itself, while still retaining structure. e.g.

    _Layout

    
    
      
        ...
        
        @RenderSection("Scripts",false/*required*/)
      
      
        @RenderBody()
      
    
    

    View

    @model MyNamespace.ViewModels.WhateverViewModel
    @section Scripts
    {
      
    }
    

    Otherwise, what you have is fine. If you don't mind it being "inline" with the view that was output, you can place the

提交回复
热议问题