Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC3: Place .js files near View instead of Scripts folder

We'd like to split out the javascript from our Razor views (so we can test). Can we locate the .js files near the views they correspond with rather then in the Scripts folder? For example, we'd like to see this in solution explorer:

MyMvcProject
    - Views
      - Home
        - About.cshtml
        - About.js

However, I don't know to references the .js file from the .cshtml view.

like image 324
Brian Low Avatar asked Feb 21 '12 01:02

Brian Low


1 Answers

For security reasons, asp.net-mvc blocks all file access to the /Views folder from URL's. This can be worked around, but I would suggest NOT doing this for security reasons.

You should generally leave your scripts in Scripts folder, particularly the system-wide ones such as jquery and the unobtrusive stuff. This is so they can be more easily updated through NuGet as new versions or bugfixes are released.

I'm not sure why you have a problem with testing and leaving them in the default location.

like image 155
Erik Funkenbusch Avatar answered Sep 20 '22 21:09

Erik Funkenbusch