Before proceeding we must look into the various folders available in the solution project. Check the image given below.
Nearly five folders were created by default when we created the MVC project.
App_Data
App_Data stores application related storage files like DB files, XML files etcetera or we can say the physical store for data happens here. The accounts like ASPNET or NETWORK SERVICE have access to this folder, however a request from an external browser is not allowed as a security measure. That means that this folder has the same accounts or permissions that exist in an ASP.Net Web site. To access a file from this folder from code behind we need to use Server.MapPath.
String _filePath = Server.MapPath("~/App_Data/test.xml");
App_Start
This folder contains a set of static classes that are used as a set of configuration logic in Global.asax before.
Content
This folder contains a default folder named "themes" that holds various jQuery version files, even included minified versions. It also stores files, like images, cascading style sheets etcetera. We can store any static files here.
Controllers
A Controller defines action methods that usually have a one-to-one relationship with possible user interactions, such as clicking a link or submitting a form. This folder holds various classes or methods that handle user's inputs or requests and respective responses. For example in Web Form projects we will have a default page or URL as "Default.aspx". A request from the user will land to this default URL then we access a web site and the processing is started. But in MVC the landing URL is mapped to classes or methods in a file called a Controller. These files names should end with the word "Controller", for example HomeController.cs.
Adding a new Controller
Right-click on the folder Controllers; click "Add" followed by "Controller". A new Add Controller box will be opened where we can enter a Controller name and select a template and Add.
The Controller that was created that inherits the Controller class is shown above. Also a default control named Index was added that returns the index view (for example: Index.cshtml).
Filters
Filters are those custom classes that provide both a declarative and programmatic way to add pre-action and post-action behavior to controller action methods. Filters are classes that inherit from the FilterAttribute base class.
ASP.NET MVC 4 provides the following types of filters: Authorization, Action, Result and Exception. We will discuss more on these topics later.
Adding a new Filter
Let's add a CustomFilter class that inherits from the FilterAttribute base class and uses that in a Controller. Now call this Filter as an attribute in Default1Controller.cs.
Add a new View for Default1Controller and name it Index.cshtml and run the project.
The output:
Models
Classes that represent the application model for MVC projects. This includes BAL, DAL etcetera. Observe that a default AccountModels.cs file was created under the Models folder. This file comprises the default Views model logics of Login View, Register, Change Password etcetera.
Images and Scripts
As usual this folder holds the images and scripting libraries.
Views
These are the user interfaces that are used to render the output to the user in a browser and can hold various file formats like the ViewPage (.html, .cshtml, .aspx), ViewUserControl (.ascx) and ViewMasterPage (.master). Each Controller will have respective View Folders. The HomeController.cs contains 3 different default Views. Master files are stored in a special folder named Shared folder.
We covered all the available folders inside a MVC project. Detailed explanations of these folders will be discussed in future articles.
Thank You !