1

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>

1 Answer 1

4

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" />
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks - How can I get the intellisense working for jquery then ? I'd like to use them both in views and in custom script files.
Include this in your javascript file: /// <reference path="~/yourdirectory/jquery-vsdoc.js" /> (where yourdirectory is... your directory)
I don't think the intellisense is breaking the code. I have got rid of the '@Scripts.Render' for vs-doc, but still i couldn't get the alert box working unless i put the '@scripts.Render' for jquery in '<head>' tag. Seems it's a mvc4 issue. please have a look at the link below. raki-tech.blogspot.co.uk/2012/12/…
It may not be the vs-doc scripts, but there is some script somewhere in the body (or late in the head) that is causing the error. I have a few MVC sites where jQuery is included at the end, just before the /body tag, and they work fine. Just remember the jQuery src has to be loaded onto the page sometime before any other scripts that use jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.