How to create MVC
MVC application folder structure
About View bags
View bags vs View data Vs Temp Data
Layout Configuration
MVC application sample using Entity framework-EF
OOP Concept.
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Asp.net c# MVC-5 Training-Day-2 of Day-9
1. AHM Pervej Kabir
Analyst Programmer
Cell:+8801757051005
Day-1: 11 September 2017
ASP.Net C#- MVC-5 Training
2. Introduction
How to create MVC
MVC application folder structure
About View bags
View bags vs View data Vs Temp Data
Layout Configuration
MVC application sample using Entity framework-EF
OOP Concept.
7. 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.
Application information
Properties
• Also Called project properties
• Consists AssemblyInfo.cs of all the build option for the project include version company name
• GUID, Compiler’s option etc.
Reference
• It is contains libraries
Application Folder
App_Data folder
• It is storing application data related files
• We can add different databases like SQL Database, SQL Compact edition database etc.
Content folder
• It contains static files like cascade style sheet (CSS), icons and images
Controller folder
• It contains controller classes
• It is responsible for handling user input and response
• MVC requires the name of all controller to end with “Controller”
Model folder
• It contains the classes thus represent the application model. Model holds and manipulate application data
View folder
• 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)
Script folder
• It contains Java Script,Azax,jquery etc. files for the application
Configuration Files
Global.asax file
Package.congf file
Web.config file
8. Layout
• The file _Layout.cshtml represent the layout of each page in the application
• It is located the shared folder inside the view folder.
9.
10. 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
11. What is Viewdata, ViewBags and TempData?
Asp.net offers us three options ViewData,ViewBags and ViewData for passing data from controller to
view.
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.
13. Layout With Razor
It used inherit method to specially content areas
o Render body
o Render Section
14. Layout Configure
In _ViewStart.cshtml
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
1)View/_ViewStart.cshtml
2) View/Home/_ViewStart.cshtml
3) View/Product/_ViewStart.cshtml
In Page: