Skip to main content

ASP.NET MVC Web Application Folder Structure Explained


ASP.NET MVC Folder Structure


ASP.NET MVC has becomes a popular framework among the developers because of clean code and folder structure. In this article, we will understand folder structure of ASP.NET MVC application.

Many new developers 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.

Based on the above scenario and to make it easier for students and developers who want to learn about MVC quickly, I have this tutorial and others to come as a starting point.

MVC framework 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 Note

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 create an ASP.NET MVC application so it will create folder structure under the project solution explorer.

Create an ASP.NET MVC Application, which creates the folder structure
Launch Visual Studio 2019 or any previous version from Start Menu as shown below


Click on Create button to create a new ASP.NET MVC Application as shown below

From the above images, we can find the folder structure from our right hand side of the window known as solution explorer as can be seeing below


From the image above we can see that ASP.NET MVC Application has the following default folder structure
1.     App_Data
2.     App_Start
3.     Content
4.     Controllers
5.     Fonts
6.     Models
7.     Scripts and
8.     Views

App_Data Folder


This folder is used to store database related file such as SQL Server .mdf files or xml files. In our case now, the folder is empty because not file is stored.

App_Start Folder

It contains various configurations files like as BundleConfig.cs, FilterConfig.cs, RouteConfig.cs, WebApiConfig.cs for your application. All these settings are registered within Application_Start method of Global.asax.cs file.
·         BundleConfig.cs – This is used to create and register bundles for CSS and JS files. By default, various bundles are added in this files including jQuery, jQueryUI, jQuery validation, Modernizr, and Site CSS.
·         FIlterConfig.cs – This is used to register global MVC filters like error filters, actions filters etc. By default it contains HandleErrorAttribute filter.
·         RouteConfig.cs – This is used to register various route patterns for your ASP.NET MVC application. By default, one route is registered here named as Default Route.

The image below shown the folder and its corresponding files as stated above

Content Folder

The content folder contains static files like CSS, Icons and image files. By default, ASP.NET comes with bootstrap and some other stylings to get us started.

Controller Folder


The folder contains C# classes that handles the requests made on our application and returns the appropriate response. By default, MVC requires us to end our controller classes with the suffix "Controller". We will discuss Controller in-depth in the subsequent post. Folder normally contains at least one file called HomeController as can be seen below.

Font Folder


The Fonts folder of an MVC application contains the custom font files that are required for our application

Model Folder


The Models folder contains our application model classes. The Models in ASP.NET MVC application are the components which contain a set of classes that are used to represent the business data as well as logic to manage the business data. So in simple word we can say that the model in ASP.NET MVC is used to manage the domain data i.e. the state of the application in memory.

Scripts Folder


The Scripts folder is the recommended folder to store Java Script files in our MVC web application. We put static and publicly accessible files for jQuery and Java Script validation files (*.js) in this folder.

Views Folder


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


In the next post (article) we will discuss more about Controller, Models, Views and html page.


Comments

Popular posts from this blog

The String.Join Method in C# Explained

The String.Join Method in C#   The string.Join concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. Overloads of string.Join Method Description Join(Char, Object[]) Concatenates the string representations of an array of objects, using the specified separator between each member. Join(Char, String[]) Concatenates an array of strings, using the specified separator between each member. Join(String, IEnumerable<String>) Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member. Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element. Join(String, String[]) Concatenates all the elements of a string array, usi...

Models in ASP.NET MVC

Models in ASP.NET MVC Explained A model is a class that contains the business logic of your application. It also used for accessing data from the database. The model class does not handle directly input from the browser. In MVC, it is the Controller that handle input from the browser directly and process the request by receiving data from the model and pass it back to view as response. It does not contain any HTML code either. It is a best practice but not mandatory for developers to not have any communications with the view directly, models should only contain a POCO ( Plain Old CLR Objects ) classes. All processing logic and communication with the view should be handled by another layer called Viewmodels. Models are also refers as objects that are used to implement conceptual logic for the application. A controller interacts with the model, access the data, perform the logic and pass that data to the view. Note that it is not mandatory, but it is a good programming...

Classes in C# Explained

C# Class Explained A class is nothing but an encapsulation of properties and methods that are used to represent a real-time entity, as explained by Guru99 . For instance, if you want to work with Guest’s data as in our previous DataDriven Web application . The properties of the Guest would be the Id, GuestName, Address, Phone number etc of the Guest. The methods would include the entry and modification of Guest data. All of these operations can be represented as a class in C# as shown below. using System; namespace CsharpnaijaClassTutorial {     public class Guest     {         public int Id { get ; set ; }         public string GuestName { get ; set ; }         public string Address { get ; set ; }         public string WhomToSee { get ; set ; }     ...