Lasse Klüver Lasse Klüver - 23 days ago 8
HTML Question

ASP.NET MVC jQuery document ready function not called

I have a Razor view containing this script:

<script type="text/javascript">
jQuery(function()
{
alert("hello world");
})
</script>


The script dosent open an alert Dialog when the page is loaded.

Portion of the BundleCfg:

bundles.Add(New ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.unobtrusive-ajax.js",
"~/Scripts/jquery.validate.unobtrusive.js"))

bundles.Add(New ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"))


At the End of the Layout Body:

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required:=False)

Answer

Try this

$(document).ready(function() {
    alert("hello world");
});

here is details: https://learn.jquery.com/using-jquery-core/document-ready/