JavaScript runtime error: '$' is undefined

If you’re developing an MVC4 app and run into this error, you probably haven’t placed your scripts in the Script section.

Looking at the _Layout.cshtml file, you’ll see one of the last lines is

@RenderSection("scripts", required: false)

which will render a section titled scripts. The following is a sample:

@section Scripts
{
    <script type="text/javascript">
        $(function () {
            alert("JQuery loaded and working!!");
        });
    </script>
}

Here’s a link to the Gu man’s discussion of sections.

Cost me about 3 hours. Hope it saves you a few!!!

Comments

Popular posts from this blog

Migrating Legacy Apps to the New SimpleMembership Provider

Windows 8 Keyboard Shortcuts

VS Removes Usings and Can't Find Types