Reputation: 105
I am having trouble with getting my page to use my javascript file. I have the file in my Areas/Export/Views/Export folder and it is called Export.js
This is how I reference it in my view
<script src="@Url.Content("~/Areas/Export/Views/Export/Export.js")"></script>
Everything I have seen online says this should work but it is not. Am I missing a reference somewhere else or what is the deal?
Thanks
Upvotes: 3
Views: 3545
Reputation: 9391
The problem is you're storing js files in your view folder. The view folder has it's own web.config which stops you from requesting static files from it.
Your options
Number 2 is best practice in my opinion. Was there a particular reason why you have the script in the view folder to begin with?
Update
To allow js files in you view folder add the following to the web.config located in your area's views folder.
<system.webServer>
<handlers>
<add name="JavaScriptHandler" path="*.js" verb="*"
preCondition="integratedMode" type="System.Web.StaticFileHandler" />
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Upvotes: 5