where should i place the js script files in a mvc application so jquery works well?

后端 未结 1 1562
醉梦人生
醉梦人生 2020-12-01 22:34

the _layout.cshtml has code lines

@Scripts.Render(\"~/bundles/jquery\")    
@Styles.Render(\"~/Content/css\")
@Scripts.Render(\"~/bundles/modernizr\") 
         


        
1条回答
  •  时光说笑
    2020-12-01 23:23

    In your layout file, the script tag to load jQuery library is included at the end of the page. But there is another section called scripts below that. So in your individual pages ( Ex : Index,View etc..) You should be putting your javascript inside the section scripts

    
     @RenderBody()
    
     @Scripts.Render("~/bundles/jquery")  
     @RenderSection("scripts", required: false)
    
    

    And in your views (Ex : Index view)

    @section scripts{
    
        
        
    
    }
    

    So when razor render the page it will be

    
        
        
        
    
    

    As long as you execute your page specific javascript which uses jQuery inside the scripts section ,you should be fine.

    0 讨论(0)
提交回复
热议问题