Proper place to load jQuery in MVC Layout view

后端 未结 1 1837
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 05:59

I\'ve created an MVC 4 using the default template, where @Script.Render(~\"bundles/jquery\") is called after @RenderBody(). As per this post, this

相关标签:
1条回答
  • 2020-12-14 06:52

    Create a new section MyScripts below all other library scripts

    _Layout

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

    MyView

    @section MyScripts {
        <script type="text/javascript">
            $("#eta_table");
            ...
        </script>
    }
    

    Now your custom page scripts only get loaded once after jQuery is loaded.

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