Ren
Ren

Reputation: 1503

Jquery-vsdoc not working using MVC4 Bundling ? and @Scripts.Render not working when included above </body> in _Layout.cshtml?

Below is the vsdoc bundle I've added to BundleConfig, and have rendered the scripts in _Layout.cshtml. Yet I couldn't get the jquery intellisense working on the views. The only way i've got it working thus far is by pasting a reference to the view where I'm using Jquery. The other thing is that even an alert box doesn't work if I render the scripts above the </body> in _Layout.cshtml. However, it works if I render it in the <head> tag. Why is it ? Any help would be greatly appreciated - thanks

**BundlesConfig**

            bundles.Add(new ScriptBundle("~/bundles/jqueryIntellisense").Include(
            "~/Scripts/jquery-{version}-vsdoc.js"));
**Layout**
</footer>
      @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryIntellisense")
    @Scripts.Render("~/bundles/modernizr")
    @RenderSection("scripts", required: false)
</body>
</html>
     **View**
<h2>Jquery Test</h2>

<script>
    $(document).ready(function () { alert("hello"); });
</script>

Upvotes: 1

Views: 958

Answers (1)

danludwig
danludwig

Reputation: 47375

The VS doc is only used by Visual Studio. You do not need to include it in a bundle. Rendering it on a web page probably what is breaking your code, causing the alert at the bottom not to fire.

To get intellisense in a script file, add a reference to it in the script file:

/// <reference path="path/from/this/script/to/jquery-1.8.2.js" />

There is a shortcut to do this. Open the script file where you want to get jQuery intellisense. Then, in the solution explorer, find your jquery-1.{whateverversion}.js file. Click and drag that file from the solution explorer to your script file and it will automatically create a /// <reference with the correct path.

To get intellisense in your views, make sure your _references.js file has a reference to jQuery:

/// <reference path="path/from/_references.js/to/jquery-1.8.2.js" />

Upvotes: 4

Related Questions