views:

467

answers:

3

Adding a script to a view generally involves something like this:

<script src="../../Scripts/jquery-1.3.1.min.js" type="text/javascript"></script>

Unfortunately, this doesn't work if the app is deployed in a virtual directory under IIS 6. The alternatives discussed here involve using Url.Content with "~" to resolve the path dynamically, but this completely breaks JS IntelliSense.

Is there a way to get around this and make IntelliSense work without losing the ability to deploy the app in a virtual directory?

+2  A: 

For deployment code you can use the google ajax apis to load JQuery. It is recommended because it help the page load time due to the use of the google CDN.

to get intellisense add this to your page

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

this will not be emitted because it is within an if(false) but intellisense will recognize it

Sruly
+1  A: 

I use something like this:

   <script src="<%= ResolveUrl("~/Content/jquery-1.2.6.js") %>" type="text/javascript"></script>   

   <%--<script src="../../Content/jquery-1.2.6.js" type="text/javascript"></script>--%>

You then have to uncomment the second reference when you want to use intellisense. It's annoying, but the only workaround I've encountered.

Justin
A: 

Check out the JScript IntelliSense FAQ on the Visual Web Developer Team Blog. The comments also reference Srully's if(false) trick.

Kevin Hakanson