I have a number of .js files that I would like to be stored in the same directories as their views (they're specific to a view - its simply to keep the javascript separate from the view's HTML)
However, adding them to the /Views/ControllerName/
directory wont work because when a request is made to the webserver for the .js file:
<script type="text/javascript" src="/Views/ControllerName/myscript.js"></script>
It would essentially be directed at the 'Views' controller which obviously doesnt exist.
Update
From what I have read, adding the following IgnoreRoute in the global.asax.cs RegisterRoutes method should permit access to any requested .js file:
routes.IgnoreRoute("{resource}.js/{*pathInfo}");
However, I cant seem to get it to work?
SOLVED
After having found and tested a number of posts (most conclusive post here) that I couldnt get to work, the following solves the puzzle:
In the Global.asax
, add the following code to the RegisterRoutes
method:
routes.IgnoreRoute("{file}.js");
There is a great post here that describes this and additional activity here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With