AHM Pervej Kabir
Day-1: 11 September 2017
ASP.Net C#- MVC-5 Training
How to create MVC
MVC application folder structure
About View bags
View bags vs View data Vs Temp Data
MVC application sample using Entity framework-EF
MVC Application Folder Structure
The MVC Framework is based on default naming, it is called convention over configuration of MVC. Models ,Views and Controllers are in different same name folder.
• Also Called project properties
• Consists AssemblyInfo.cs of all the build option for the project include version company name
• GUID, Compiler’s option etc.
• It is contains libraries
• It is storing application data related files
• We can add different databases like SQL Database, SQL Compact edition database etc.
• It contains static files like cascade style sheet (CSS), icons and images
• It contains controller classes
• It is responsible for handling user input and response
• MVC requires the name of all controller to end with “Controller”
• It contains the classes thus represent the application model. Model holds and manipulate application data
• It contains HTML files to the user interface which called view
• For each controller view folder contains individual folder
• Home folder is use for storing application pages like home page ,about page etc.
• Share folder used to store views shared between controllers (Layout Pages)
• It contains Java Script,Azax,jquery etc. files for the application
• The file _Layout.cshtml represent the layout of each page in the application
• It is located the shared folder inside the view folder.
About View Bag
It is dynamic view datadictionery
It is dynamic the project
Asp.net MVC offer us to use ViewBag for passing data from controller to view
Create A model : AboutModel.CS Edit HomController .CS Edit View about.cshtmal
What is Viewdata, ViewBags and TempData?
Asp.net offers us three options ViewData,ViewBags and ViewData for passing data from controller to
ViewData and View Bags are almost similar and TempData performs additional responsibility.
Similarity between Viewdata and ViewBags
Helps to maintain data when you move from controller to view
Used to passed data controller to view
Short life means value becomes null when redirect occur
It’s a communication mechanism within he server call
Difference between Viewdata and ViewBags
ViweData is a dictionary of objects that is derived fromViewDataDictionary class and accessible using
string as keys
ViewBags is a dynamic property that takes advantage of new dynamic feature in latest C#.4.
View Data Requires typecasting for complex data type and check for null values to avoid error.
ViewBags doesn’t require typecasting for complex data type.
Layout With Razor
It used inherit method to specially content areas
o Render body
o Render Section
This file will execute at the start of each view’s rendering
Any code contained within the code block in tis file will execute before any code in the view.
Typically, this file will set the layout template to be used by the view in the application
An MVC Application can have multiple _ViewStart.cshtml files.
The order in which these file execute is dependent upon the location of files in the folder hierarchy and the particular view being
The MVC runtime will first execute the code the _ViewStart.cshtml file locate on the root of the view folder
It will then work its way up the folder hierarchy, execute the code in each _ViewStart.cshtml file it finds along the way.
For Example, we may have _ViewStart.cshtml files in the following locations