What is the purpose of automatically generated directories in an ASP.NET MVC project?

Asked

Viewed 475 times

6

In Visual Studio Community 2015 when we create a new project in ASP.NET MVC in the project is automatically generated the following directory structure, see the image below:

Estrutura do projeto MVC

Being in total eight directories.

Question

I would like to know what is the purpose of each directory that was automatically generated?

  • Controllers, Models and Views is for use of the MVC structure, App_data I believe is for various data used by the framework, maybe since session as temporary. The briefcase fonts it was you who added?

  • The briefcase fonts was also created automatically by the IDE.

  • 2

    Interesting, I left an upvote ;) See you later

2 answers

4

This is the basic and standard structure created for a new ASP.NET MVC project. To work, you usually need folders App_Start, Views, Models and Controllers. More experienced developers can choose to create a completely empty project and add structures as needed. However, because it is MVC probably the Model, Controllers and Views folders will be.

The most common folder is APP_Data which is generally used for file-based database storage, such as .dbf or .mdf. This is a folder that IIS will deny direct access by containing sensitive data. For example if you put image files and try to deliver to client will not get access in a trivial way.

The briefcase App_Start is where by default the Routes, Bundles and Filters configuration files are created.

The briefcase Content is where style sheet(CSS) files are created and images can be added as well.

Controllers is where the controllers are created, both ApiController regarding common controllers.

Models is where is created the Models files (can be Viewmodels or Models), which are representations of business entities for example, according to the architecture. I’ve seen cases of not having this folder, because the models are in another Assembly(dll).

In that folder fonts are source files(typography).

Scripts are Javascript libraries(jquery, jqueryval etc)

Views are the . cshtml files.

4


First of all, I must point out that most folders are suggestions, and do not necessarily need to be used as they are. That said, I will make a brief explanation of each folder.

App_data

This folder is indicated to save the physical files if you are using it. For example: I will upload a spreadsheet to my website and want to save it somewhere. Microsoft suggests that you use this folder.

App_start

This folder contains the classes that are executed when your application starts. It usually comes with the files Bundleconfig.Cs, Filterconfig.Cs and Routeconfig.Cs by default (if using the template sample of Visual Studio).

Content

This folder is the place indicated to add the content files, such as css, images, icons, etc.

Controllers

By default, your controllers should be created in this folder. This standardization is important for reasons of routes and connection with Views. This pattern is so recommended, that Visual Studio has a function called Go To View, where he opens the View referring to that Action.

fonts

Location indicated to save the fonts used in your application. These are those fonts to change the same letter, those files with the extensions .eot, .svg, .woff, etc..

Models

Folder indicated to save the templates of your application. Of course, it is an indication, and if you uses the Repository standard (I don’t know why the hell you would do that), you wouldn’t even have to use that folder. However, I wouldn’t advise doing that.

Scripts

I think this folder should be the most obvious one, but yes. This folder is the place to save Scripts of its application. And yes, the Scripts what I mean are the archives .js, like the jQuery.js, bootstrap.js, etc..

Views

By default, your Views should be created in this folder. This standardization is important for reasons of routes and connection with Controllers. This pattern is so recommended, that Visual Studio has a function called Go To Controller, where he opens the Controller concerning this View.

As Views are those files with the extension .cshtml, that is, the layout of your application.

There is one more folder that an application usually has (manually created), which is the Viewmodel:

Viewmodels

In this folder your Viewmodels. In case you don’t know what I’m talking about, read these answers you’ll understand better.

As I said earlier, these folders are suggestions from Microsoft. It is not necessary to use in the suggested way. However, if you change the most important folders (App_start, Controllers and Views), you will have serious problems if you do not know what you are doing. This is because the routes (I am not talking about the Routeconfig.Cs) of the application are configured to this default, but if you make changes in the folder but do not change the routes correctly, surely your application will give error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.