Why jquery doesn't work on the page defined in layout

I have a layout razorand it loads css jquery etc.
When I add a controller action view, I set the layout as _Layout.cshtml
But jquery does not work on this page.
So I have to add @Scripts.Render("~/bundles/jquery")to every view.
Why is imported jquery not inherited from _Layout.cshtml? This is normal?

+4
source share
1 answer

This should be near the bottom of _Layout.cshtml:

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

This should be in your child's view:

@section scripts {
    @Scripts.Render("~/scripts/jquery.infinitescroll.js") // Or some other script
}

( jquery) , . script, jquery. , :

@section scripts {
    @Scripts.Render("https://maps.googleapis.com/maps/api/js?key=&sensor=false")
    <script src="~/scripts/google-maps-3-vs-1-0.js"></script>
    <script>
        Stuff here
    </script>
}
+7

Source: https://habr.com/ru/post/1502688/


All Articles