title: In ASP.NET MVC, adding a script reference throws exception
body: <p>On a skeleton ASP.MVC that Visual Studio creates, I add a script tag to my head section in Site.Master:</p>
  
  <pre><code>&lt;script src="~/Scripts/jquery-1.3.2.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>This causes the page to not render.  In my case, I had a custom controllerfactory and the base method GetControllerInstance threw an exception:</p>
  
  <blockquote>
    <p>The controller for path
    '/~/Scripts/jquery-1.3.2.js' could not
    be found or it does not implement
    IController.</p>
  </blockquote>
  
  <p>Using "../../Scripts/jquery-1.3.2.js" for the src does not work either.</p>
  
  <p>The only way it works is:</p>
  
  <pre><code>&lt;script src="&lt;%= Url.Content("~/Scripts/jquery-1.3.2.js") %&gt;"
      type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Then of course, the intellisense does not work for jquery.  So I have to resort to adding the hack:</p>
  
  <pre><code>&lt;% if (false) { %&gt;
      &lt;script src="~/Scripts/jquery-1.3.2.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>which the hotfix was supposed to fix according to <a href="http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx" rel="nofollow noreferrer">ScottGu</a></p>
  
  <p>A line above is a link to a stylesheet:</p>
  
  <pre><code>&lt;link href="~/Content/Site.css" rel="stylesheet" type="text/css" /&gt;
  </code></pre>
  
  <p>For some reason, that works fine.  Whether I use the virtual or relative path, I can see that the resulting url on the page is "Content/Site.css".  The same can't be said for the jquery url.  jquery link is returned as is - the jquery url is returned on the page containing the "~" or the "../..".</p>
  
  <p>Can someone tell me what is going on?
  Thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks to the commenters, I remembered that ~ is an asp.net thing.  My only question is then why doesn't the same issue exist for the stylesheet?  The link tag above, for example, I can put ~ or relative paths and it always comes out right.  Where is the magic?</p>