Proper place to load jQuery in MVC Layout view

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.

Leave a Comment