-1

I just created ASP .NET MVC4 project by default and put some code from this sample and it is not working at all.

Any clues?

Error:

Uncaught ReferenceError: jQuery is not defined jquery.cycle.all.latest.js:918 Uncaught ReferenceError: $ is not defined

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET MVC Application</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <style type="text/css">
        .slideshow {
            height: 232px;
            width: 232px;
            margin: auto;
        }

            .slideshow img {
                padding: 15px;
                border: 1px solid #ccc;
                background-color: #eee;
            }
    </style>

    <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('.slideshow').cycle({
                fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            });
        });
    </script>

</head>
<body>
    <header>
        <div class="content-wrapper">
            <div class="float-left">
                <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>
            </div>
            <div class="float-right">
                <section id="login">
                    @Html.Partial("_LoginPartial")
                </section>
                <nav>
                    <ul id="menu">
                        <li>@Html.ActionLink("Home", "Index", "Home")</li>
                        <li>@Html.ActionLink("About", "About", "Home")</li>
                        <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                    </ul>
                </nav>
            </div>
        </div>
    </header>
    <div id="body">
        @RenderSection("featured", required: false)
        <section class="content-wrapper main-content clear-fix">
            @RenderBody()
        </section>
    </div>
    <footer>
        <div class="content-wrapper">
            <div class="float-left">
                <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p>
            </div>
        </div>
    </footer>

</body>
</html>
NoWar
  • 36,338
  • 80
  • 323
  • 498

1 Answers1

1

It doesn't look like you include the jQuery library. You need to add this to your <head> section:

<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
Steve
  • 8,609
  • 6
  • 40
  • 54
  • Question: Has ASP .NET MVC4 jQuery included? Hmmm – NoWar Apr 17 '13 at 23:30
  • Most of the MVC4 project templates should have it by default. – jmoerdyk Apr 17 '13 at 23:31
  • @jmoerdyk Exactly! So I have used the one provided by MS. – NoWar Apr 17 '13 at 23:32
  • @Metropolitan - Well, it's easy enough to find out. Just take a look at your page source and look if it is in there. – Steve Apr 17 '13 at 23:32
  • 2
    But you're not including it in the page. If your project has it, try adding a `@Scripts.Render("~/bundles/jquery")` on the line before you include the plugin – jmoerdyk Apr 17 '13 at 23:32
  • @jmoerdyk QUestion: but does it mean that ` bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js"));` is not working at all if I have to include jQuery directly? – NoWar Apr 17 '13 at 23:41
  • 1
    All that line in the Bundles.Config does is _define_ the bundle, to use the scripts in that bundle, you still need to render that bundle to the page. – jmoerdyk Apr 17 '13 at 23:43
  • @jmoerdyk I didn't know it. Thank you!! Hey could you provide any link to read about it more please? – NoWar Apr 17 '13 at 23:48