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.
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
Post a Comment