<p>For example, if I have a page located in Views/Home/Index.aspx and a JavaScript file located in Views/Home/Index.js, how do you reference this on the aspx page?</p>

<p>The example below doesn't work even though the compiler says the path is correct</p>

<pre><code>&lt;script src="Index.js" type="text/javascript"&gt;&lt;/script&gt;
</code></pre>

<p>The exact same issue has been posted here in more detail:
<a href="http://forums.asp.net/p/1319380/2619991.aspx" rel="nofollow noreferrer">http://forums.asp.net/p/1319380/2619991.aspx</a></p>

<p>If this is not currently possible, will it be in the future? If not, how is everyone managing their javascript resources for large Asp.net MVC projects? Do you just create a folder structure in the Content folder that mirrors your View folder structure? YUCK!</p>

[{'answer_id': 79246, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 2, 'selected': False, 'text': '<p>You can use the VirtualPathUtility.ToAbsolute method like below to convert the app relative url of the .js file to an absolute one that can be written to the page:</p>\n\n<pre><code>&lt;script type="text/javascript" src="&lt;%=VirtualPathUtility.ToAbsolute("~/Views/Home/Index.js") %&gt;"&gt;&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 79267, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': "<p>You should have separated folder structure for scripts. For example JavaScript folder under application root. Storing js files with views is not only affects you with path resolving issues but also affects security and permissions thins. Also it's much more easier later to embed JS files as assembly resources if you will decide to deploy some of your application parts separately in future when they are stored in dedicated subfolder. </p>\n"}, {'answer_id': 79772, 'author': 'Vyrotek', 'author_id': 10941, 'author_profile': 'https://Stackoverflow.com/users/10941', 'pm_score': 2, 'selected': True, 'text': '<p>For shared javascript resources using the Content folder makes sense. The issue was I was specifically trying to solve was aspx page specific javascript that would never be reused. </p>\n\n<p>I think what I will just have to do is put the aspx page specific javascript right onto the page itself and keep the shared js resources in the Content folder.</p>\n'}, {'answer_id': 80638, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Here\'s a nice extension method for HtmlHelper:</p>\n\n<pre><code>public static class JavaScriptExtensions\n{\n    public static string JavaScript(this HtmlHelper html, string source)\n    {\n        TagBuilder tagBuilder = new TagBuilder("script");\n        tagBuilder.Attributes.Add("type", "text/javascript");\n        tagBuilder.Attributes.Add("src", VirtualPathUtility.ToAbsolute(source));\n        return tagBuilder.ToString(TagRenderMode.Normal);\n    }\n}\n</code></pre>\n\n<p>Use it like this:</p>\n\n<pre><code>&lt;%=Html.JavaScript("~/Content/MicrosoftAjax.js")%&gt;\n</code></pre>\n'}, {'answer_id': 8094695, 'author': 'Pablo Montilla', 'author_id': 83169, 'author_profile': 'https://Stackoverflow.com/users/83169', 'pm_score': 0, 'selected': False, 'text': "<p>If you re-route your pages to a custom RouteHandler, you can check for existence of files before handling the RequestContext to the MvcHandler class.</p>\n\n<p>Example (not complete):</p>\n\n<pre><code>public class RouteHandler : IRouteHandler\n{\n    public IHttpHandler \n    GetHttpHandler(RequestContext requestContext)\n    {\n        var request = requestContext.HttpContext.Request;\n\n        // Here you should probably make the 'Views' directory appear in the correct place.\n        var path = request.MapPath(request.Path); \n        if(File.Exists(path)) {\n            // This is internal, you probably should make your own version.\n            return new StaticFileHandler(requestContext);\n        }\n        else {\n            return new MvcHandler(requestContext);\n        }\n    }\n}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/79215', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10941/']