4

i am new to asp.net MVC4 architecture i am get stuck with following thing please help me.

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")

<script type="text/javascript">
$(function () {
    $("#sections").tabs();
    //here i am getting error that Object[object object] has not method tabs    
});
</script>

<div id="sections">
    <ul>
        <li><a href="#section-1">section-1 </a></li>
        <li><a href="#section-2">section-2 </a></li>
    </ul>
        <div id="section-1">
        section-1 content............  
        </div>
        <div id="section-2">
        section-2 content............ 
        </div>
    </div>

THANKS IN ADVANCE......

savy
  • 164
  • 2
  • 2
  • 12

1 Answers1

10

You probably have included the ~/bundles/jquery bundle twice. Checkout your ~/Views/Shared/_Layout.cshtml file. At the end you probably have the following:

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>

So the jQuery bundle is already included in your page. You should not include it a second time inside your view. You need only the ~/bundles/jqueryui bundle:

@Scripts.Render("~/bundles/jqueryui")

<script type="text/javascript">
$(function () {
    $("#sections").tabs();
    //here i am getting error that Object[object object] has not method tabs    
});
</script>

<div id="sections">
    <ul>
        <li><a href="#section-1">section-1 </a></li>
        <li><a href="#section-2">section-2 </a></li>
    </ul>
    <div id="section-1">
        section-1 content............  
    </div>
    <div id="section-2">
        section-2 content............ 
    </div>
</div>

UPDATE:

Here's a full example of how the structure of your view might look like:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Foo</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
</head>
<body>
    <div id="sections">
        <ul>
            <li><a href="#section-1">section-1 </a></li>
            <li><a href="#section-2">section-2 </a></li>
        </ul>
        <div id="section-1">
            section-1 content............  
        </div>
        <div id="section-2">
            section-2 content............ 
        </div>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    <script type="text/javascript">
        $("#sections").tabs();
    </script>
</body>
</html>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • thanks for reply...but when i remove @Scripts.Render("~/bundles/jqueryui") this line it says $ is not defined... – savy Oct 17 '12 at 11:04
  • 1
    You should not remove the `@Scripts.Render("~/bundles/jqueryui")` line. You should remove the `@Scripts.Render("~/bundles/jquery")` line if it already exists in your `_Layout.cshtml`. Is this the case? I have updated my answer with an example of how your view might look. – Darin Dimitrov Oct 17 '12 at 12:22
  • How do you do this , when you are not using bundler? (or any other minifcation.) I get the same behavior as the OP. Its included in the _Layout, but then I also have to include it in every page I want to use JavaScript in. Else I get $ not defined. – Rex Whitten Jul 15 '13 at 15:36