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

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

ASP.NET MVC Views

Views in ASP.NET MVC Application explained Find a related article By  Steve Smith  and  Luke Latham from Microsoft Corporation here In the Model-View-Controller (MVC) pattern, the  view  handles the application's data presentation and user interaction. A view is an HTML template with embedded  Razor markup . Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET MVC, views are  .cshtml  files that use the  C# programming language  in Razor markup. Usually, view files are grouped into folders named for each of the application's  controllers . The folders are stored in a  Views  folder at the root of the application as shown: The  Home  controller is represented by a  Home  folder inside the  Views  folder.  The  Home  folder contains the views for the  About ,  Contact , and  Index...

ASP.NET MVC Routing

ASP.NET MVC Routing ASP.NET MVC routing is a pattern matching system that is responsible for mapping incoming browser requests to specified MVC controller actions. When the ASP.NET MVC application launches then the application registers one or more patterns with the framework's route table to tell the routing engine what to do with any requests that matches those patterns. When the routing engine receives a request at runtime, it matches that request's URL against the URL patterns registered with it and gives the response according to a pattern match. Routing pattern is as follows A URL is requested from a browser, the URL is parsed (that is, break into controller and action), the parsed URL is compared to registered route pattern in the framework’s route table, if a route is found, its process and send response to the browser with the required response, otherwise, the HTTP 404 error is send to the browser. Route Properties ASP.NET MVC routes are res...