Gary Davis' Blog

DotNET/PayPal Development and other Techie Stuff
posts - 45, comments - 139, trackbacks - 0

How to Enable jQuery Intellisense in Your MVC 3 Razor Code

You probably include your <script> to pull in the jQuery JavaScript in your layout.cshtml (master page in Razor), perhaps something like this:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.6.2.min.js" type="text/javascript"></script>
 

But your code pages that use jQuery do not show Intellisense. To enable Intellisense, add this to the top of the pages so Visual Studio has a reference to the vsdoc which is hosted by the Microsoft CDN:

@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.6.2.min.js" type="text/javascript" />}
 

The if statement will prevent the script tag from being emitted to the browser since it is only needed for Visual Studio development.jquery

It is not necessary to specify the path to the vsdoc file since Visual Studio knows to look for the vsdoc in the same location and use it if it finds it.

The Intellisense is shown based on deleting then typing the open paren at the point indicated.

BTW, the $(function() at the top of the example is a common shorthand for $(document).ready(function().

The CDN used is the Microsoft Ajax Content Delivery Network and they changed the domain from ajax.microsoft.com to ajax.aspnetcdn.com to improve performance and prevent microsoft.com cookie transmission.

The CDN also has the files for the jQueryUI .js and .css for the themes.

<link type="text/css" rel="Stylesheet" 
    href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.14/themes/redmond/jquery-ui.css" />
<script type="text/javascript" 
    src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.14/jquery-ui.min.js"></script>
 

Note that the current versions of these files at this time is 1.6.2 for jQuery and 1.8.14 for jQueryUI.

Print | posted on Monday, May 30, 2011 12:00 AM | Filed Under [ Programming ]

Feedback

Gravatar

# re: How to Enable jQuery Intellisense in Your MVC 3 Razor Code

Thank you so much. I needed this bad. Great contribution.
12/7/2012 7:43 PM | James Bailey

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 4 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET