In my mvc 3 application, assuming I have a folder structure like \\Views\\Account\\js\\custom.js
How do I add that file to my view in the Account\\index.c
The web.config
file in the /Views folder restricts all access to files in the folder by default:
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
You could change that, but it's probably more secure overall to not store the assets in the views folder.
You can use a UrlHelper
:
<script src="@Url.Content("~/view/account/js/custom.js")" type="text/javascript"></script>
Add this under your views web.config Handlers section
<add name="JavaScriptHandler" path="*.js" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" />
The best way is to use T4MVC - http://mvccontrib.codeplex.com/wikipage?title=T4MVC No need to use magic strings...