ASP.NET MVC creates a default file structure for you when you create a new project. It includes a Scripts directory, which contains the MS AJAX and jQuery .js files, and a content directory, which contains a Master page and CSS files. I find this to be extremely cumbersome and it forces me to jump around a lot. Storing shared CSS and JavaScript files in those locations is fine in my opinion. But if you are using View specific CSS or JavaScript files, you should put them alongside your view page in the Views directory. This allows you to quickly find the file you want to work on.
The Lounge
Books I’ve worked on
Hosted By
Contributors
Links
-
Recent Posts
What I'm Doing...
- More details about display:table. http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/ 3 hrs ago
- Right, IE8 supports "display:table". But @stefsull is right, it depends on your browser requirements. 3 hrs ago
- People who find creating css tables daunting, have you tried display: table,table-row,table-cell ? 5 hrs ago
- More updates...
Powered by Twitter Tools

6 Comments
Hopefully this makes it through
While I think that’s an excellent idea for organization, I think that the Javascript Auto Include plugin for Rails does it up a little more elegantly. It creates a directory structure for you to place your JS files organized by view.
If only there were something similar for MVC
I put some explanatory code in my response: http://bit.ly/pR5Na
To increase performance you should be bundling your scripts and css into as few files as possible. This is to reduce calls from the client to the server and speed up page load time. Therefore splitting your files up is not the greatest idea.
Glyn: There’s nothing preventing you from concatenating your CSS and JS files either in a post-build step or server-side using a handler. In that case, it doesn’t really matter where the files are physically.
This is some kind of Separation of Concerns. I prefer to store scripts in scripts folder, css and images in contents folder and c# code – in some other folders. But you can mix all of them – place views with controller and other related files in the same folder. And even you can easily use codebehind files and make calls to DB too.
*typo*
..make calls to DB in views too
This sounds like a good idea, but when I tried to do it, I couldn’t seem to access the JavaScript files stored alongside aspx pages in the Views folder. I’m trying to diagnose it now, but I’m thinking it’s because routing is blocking a direct request for the .js file inside the views folder. Any ideas, anyone?
Post a Comment