0

I'm making an app with ASP.Net core (1.1), and for some reason my JQuery is giving me some very strange behavior.

In my view page (Page.cshtml) I have:

<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<script src='https://cdn.rawgit.com/pguso/jquery-plugin-circliful/master/js/jquery.circliful.min.js'></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

But I was getting JQuery errors even without this code section, so I don't think it's necessary, but just leaving it in for now.

Anyway, in my Layout file (_Layout.cshtml) I have this:

<!-- jQuery-->
<script>console.log("Here");</script>
<script src="~/lib/jquery/dist/jquery.js"></script>

Enclosed in:

<environment names="Development">

and:

<body class="theme-1 sidebar-offcanvas">

tags. The errors I'm getting are:

Uncaught ReferenceError: jQuery is not defined
    at bootstrap-toggle.js:180
Uncaught ReferenceError: jQuery is not defined
    at jquery.circliful.min.js:1
Uncaught ReferenceError: jQuery is not defined
    at jquery-ui.js:314
Uncaught ReferenceError: $ is not defined
    at AutoComplete.js:1

Any advice on how I can fix this is greatly appreciated. Apologies for the long-winded nature of this question, this has been a long, ongoing, and incredibly frustrating issue for me.

  • 1
    You are probably loading your Page.cshtml scripts before loading jQuery, check the output of your html, and make sure jQuery is loaded first – Hipny Aug 16 '17 at 20:38
  • If it's in the _Layout.cshtml file shouldn't JQuery be loaded prior to Page.cshtml even beginning? And even then, wouldn't the script I put at the start of the page to load JQuery and JQuery-ui work to load JQuery to the page? – Matthew Gower Aug 16 '17 at 20:45
  • 1
    Well, it all depends where your @ RenderBody is situated. If you load jquery after @ RenderBody, and you haven't placed your scripts into a @ Script section in your Page.cshtml, your Page.cshtml scripts will be rendered before jquery – Hipny Aug 16 '17 at 20:48
  • Here's an article from Scott Guthrie about sections in razor: http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx It should help you understand sections. – Hipny Aug 16 '17 at 20:51
  • Thank you very much. I fixed it by moving the Jquery reference in _Layout.cshtml above the @RenderBody statement. – Matthew Gower Aug 16 '17 at 20:55
  • Possible duplicate of [JQuery - $ is not defined](https://stackoverflow.com/questions/2194992/jquery-is-not-defined) – Vidiya Prasanth Pappannan Aug 16 '17 at 22:16

0 Answers0