Monday, February 25, 2013

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!!!

1 comment:

aalia lyon said...

Its Superb blog , if Rundll error problem go through this link and get free from error.
How To Remove Rundll Error
Thank you
Aalia lyon