Understanding ASP.NET MVC Folder Structure

Background

Day by day ASP.NET MVC is becoming a popular framework among the developers because of clean code and folder structure. In the first article of ASP.NET MVC article series we will understand folder structure of ASP.NET MVC application.

Many new developer and students are struggling to learn ASP.NET MVC in quick time and in MVC lots of technologies are used like JavaScript , jQuery , AngularJS, Typescript, Dapper, Entity framework and much more because of this developers and students get confused how to start learning.
 
By considering above problem and to help students and developers who want to learn quick about MVC, I have decided to start series of articles on ASP.NET MVC.

MVC And Convention standard 

ASP.NET MVC applications, by default, depends heavily on conventions. This allows developers to avoid having to configure and specify things that can be inferred based on convention by adding code through Scaffolding.

For instance, MVC uses a convention-based directory-naming structure when resolving View templates and this convention allows you to omit the location path when referencing views from within a Controller class.

MVC is designed around some sensible convention-based defaults that can be overridden as needed.

This concept is commonly referred to as "convention over configuration" with popular concepts of Ruby on Rails programming language. The convention over configuration concept implemented in ASP.NET MVC with the help of following main directories.
  • Controllers
  • Models
  • Views
Key points
  • Each controller name ends with suffix controller.
  • The single view directory can be used for entire application.
  • By default all directories (folder) created with name of controller name.
Let's add the ASP.NET MVC application so it will create folder structure under the project solution explorer.

Step 1:
Create MVC Application To Create Folder structure.
  1. "Start", then "All Programs" and select "Microsoft Visual Studio 2015".

  2. "File", then "New" and click "Project..." then select "ASP.NET Web Application Template", then provide the Project a name as you wish and click on OK .

     
In the preceding project solution explorer you have seen different folders and files. The preceding folder structure may be different according to your MVC project template, so let us learn about major folders in brief as in the following:
  • App_Data
  • App_Start
  • Content
  • Controllers
  • Models
  • views
  • Script
App_Data

This folder is used to store file based database such as SQL Server .mdf files or xml files, etc as in the following image.



Controller

This folder contains the controller and their methods. The controller is responsible for processing the user request and return output.



Models

This folder contains the class files for entities or properties used to store the input values.



You can rename the folder Model and you can give any name as you wish It is not mandatory that the folder name should be Models, however, model name is only for better naming conventions. Also, Model can be created in separate class library project.

View

This folder contains the UI pages including shared page, .CSHTMl, .VBHTML, HTML, aspx pages that show the output to the end user.



Content

This folder is used to store files related to design and UI such as CSS files, images which is required for UI.



Script

This folder contains the Script files such as JavaScript ,jQuery ,AngularJS ,TypeScript, etc.



From preceding example we have learned what is the folder structure architecture with the use of each folder.

Note:

It is not mandatory that you should use above folder structure and naming conventions. You can rename it and follow different folder structure as you wish.

To learn more about MVC basic in terms of understanding the preceding folder structure practically please refer the following video series.

MVC Basic Videos.

Summary

I hope this article is useful for all readers, if you have a suggestion then please contact me. To learn ASP.NET MVC step by step please refer the this article.


Similar Articles