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...

Most Popular Programming Languages in 2020

Most Popular Programming Languages in 2020 In this blog post, you will learn about the most popular programming languages in 2020 for creating the best web applications. Check its pros and cons. Analyzed by technostacks Not very long ago, just a few people were considered to be computer programmers, and the general public viewed them with awe. In this digital age that we are now living in, however, a large number of IT jobs need a solid grasp of one or more programming languages. Whether one wants to develop a mobile app or get a certification for having programming knowledge, or even to learn new skills, one needs to opt for the right programming language. Below mentioned eight most popular programming languages which are in demand for software development and web applications. This is the most used programming languages in 2019 and will be in 2020. For each, there is little information about the language, benefits and its complexity, as well as about its usage. One must...

HashTable in C# with Example

  HashTable in C# with Example Hashtable  is used to store a collection of key/value pairs of different  data types  and are organized based on the hash code of the key.   Generally, the hashtable object will contain buckets to store elements of the collection. The bucket here, is a virtual subgroup of elements within the hashtable and each bucket is associated with a hash code, which is generated based on the key of an element.   In C#, hashtable is same as a  dictionary  object but the only difference is that the  dictionary  object is used to store a key-value pair of same  data type  elements.   When compared with  dictionary  object, the hashtable will provide a lower performance because the hashtable elements are of object type so the boxing and unboxing process will occur when we are storing or retrieving values from the hashtable.   C# HashTable Declaration Hashtable is a non-generic type...