views:

85

answers:

2

Due to how paths relate to VS resolving the path to a JS file and then how the actual path at runtime is resolved via the browser, I've currently got the following placed at the top of my Master Page within my application so that all my views have the appropriate JS intellisense and resolve correctly for execution:

<% if (false) { %>
    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<% } else { %>
    <script src="<%= ResolveUrl("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/MicrosoftAjax.debug.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/MicrosoftMvcAjax.debug.js") %>" type="text/javascript"></script>
<% } %>

Is this may how others are doing it or is there some crazy better way that's going to make me look like an ass? Thanks!

+2  A: 

If it's good enough for Scott Guthrie, then I'd consider it the correct way to do it (for now, they could always fix this in VS 2010!).

John Rasch
lol, I wish I found him doing that sooner before I figured it out, woulda saved me some cycles :)
James Alexander
A: 

Yes, I agree that's the correct solution. Just throwing it into the master page won't be enough though - you also need to put it into all the partial view files you may have. I just blogged about this yesterday with rather extensive comments on the background.

If you have many script files, it might be a good idea to group all these into one .js file and keep including that, so in case of another script being added you don't have to go around pasting it everywhere. Of course, if you don't use partial (ascx) views, none of this is an issue. But if you need this, take a look at the Intellisense FAQ question 3.

Jouni Heikniemi