Alex Rivera | Logout

ASP.net MVC 3 Razor - jQuery Intellisense

Asked 2011-03-02T22:50:43.020
15

I am using Visual Studio 2010 / ASP.net MVC 3 with the Razor View Engine. I created a new Project with the Internet Application template. What do I need to do to get Intellisense working?

Edit
Report

2 Answers

31

If that's jQuery specific as the title specifies, trying adding line to the tag in the Views/Shared/_layout.cshtml (or .vbhtml) file:

@if (false) { <script src="../../Scripts/jquery-1.4.4-vsdoc.js" type="text/javascript"></script> }

This will reference the intellisense file to VisualStudio and still will not reference it in runtime.

Just remember, point to the vsdoc file relatively to the file you put this code in. Any code like ~/Url.Content() or any other runtime code will not be visible to VS for intellisense.
That's exactly why if (false) hides the script reference from runtime (the if block isn't executed), but doesn't hide it from VS intellisense (and provide another reference using Url.Content() or so to the .min.js file).

answered 2011-03-02T23:16:59.687
4

I found good explanation which worked for me at: http://theycallmemrjames.blogspot.com/2011/03/jquery-intellisense-with-aspnet-mvc-and.html

These lines:

 @if (false) 
{ 
    <script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script> 
    <script src="../../Scripts/jquery-ui.min.js" type="text/javascript"></script> 
}

should be added to every view (where intellisense is needed). This will enable intellisense but will not add the second reference at runtime.

answered 2011-03-23T17:23:05.137

Your Answer