SlideShare a Scribd company logo
1 of 22
Download to read offline
ASP.NET MVC
1
MVC
•NET Framework – A technology introduced in 2002
which includes the ability to create executables,
web applications, and services using C#
(pronounced see-sharp), Visual Basic, and F#.
•ASP.NET – An open-source server-side web
application framework which is a subset of
Microsoft’s .NET framework. Their first iteration of
ASP.NET included a technology called Web Forms.
•ASP.NET WebForms – (2002 – current) A
proprietary technique developed by Microsoft to
manage state and form data across multiple pages.
2
MVC
•ASP.NET MVC is Microsoft’s framework for
developing fast web applications using their .NET
platform with either the C# or VB.NET language.
•MVC is an acronym that stands for:
• (M)odel – Objects that hold your data.
• (V)iew – Views that are presented to your users,
usually HTML pages or pieces of HTML.
• (C)ontroller – Controllers are what orchestrates the
retrieving and saving of data, populating models, and
receiving data from the users.
3
MVC
•An alternative to ASP .NET Web Forms
•Presentation framework
• Lightweight
• Highly testable
•Integrated with the existing ASP .NET features:
• Master pages
• Membership-Based Authentication
4
ASP .NET MVC Framework Components
• Models
• Business/domain logic
• Model objects, retrieve and store model state in a
persistent storage (database).
• Views
• Display application’s UI
• UI created from the model data
• Controllers
• Handle user input and interaction
• Work with model
• Select a view for rendering UI
5
Advantages of MVC
•Advantages:
• Easier to manage complexity (divide and conquer)
• It does not use server forms and view state
• Front Controller pattern (rich routing)
• Better support for test-driven development
• Ideal for distributed and large teams
• High degree of control over the application behavior
6
Advantages of MVC
ASP.NET MVC has a separation of concerns.
Separation of concerns means that your business
logic is not contained in a View or controller. The
business logic should be found in the models of your
application. This makes web development even
easier because it allows you to focus on integrating
your business rules into reusable models.
7
Advantages of MVC
ASP.NET MVC provides testability out of the box.
Another selling point is that ASP.NET MVC allows
you to test every single one of your components,
thereby making your code almost bulletproof. The
more unit tests you provide for your application, the
more durable your application will become.
8
Advantages of MVC
ASP.NET MVC has a smaller “View” footprint.
With WebForms, there is a server variable called
ViewState that tracks all of the controls on a page. If
you have a ton of controls on your WebForm, the
ViewState can grow to become an issue. ASP.NET
MVC doesn’t have a ViewState, thus making the
View lean and mean.
9
Advantages of MVC
ASP.NET MVC has more control over HTML.
Since server-side controls aren’t used, the View can
be as small as you want it to be. It provides a better
granularity and control over how you want your
pages rendered in the browser.
10
ASP .NET MVC Features
•Separation of application tasks
• Input logic, business logic, UI logic
•Support for test-driven development
• Unit testing
• No need to start app server
•Extensible and pluggable framework
• Components easily replaceable or customized(view
engine, URL routing, data serialization,…)
11
ASP .NET MVC App Structure
•URLs mapped to controller classes
•Controller
• handles requests,
• executes appropriate logic and
• calls a View to generate HTML response
•URL routing
• ASP .NET routing engine (flexible mapping)
• Support for defining customized routing rules
• Automatic passing/parsing of parameters
12
ASP .NET MVC App Structure
•No Postbackinteraction!
•All user interactions routed to a controller
•No view state and page lifecycle events
13
Layout of an MVC project
When you create a new MVC project, your solution
should have the following structure in your Solution
Explorer.
14
Layout of an MVC project
15
Layout of an MVC project
16
• App_Data – While I don’t use this folder often, it’s meant to hold
data for your application (just as the name says). A couple of
examples would include a portable database (like SQL Server
Compact Edition) or any kind of data files (XML, JSON, etc.). I prefer
to use SQL Server.
• App_Start – The App_Start folder contains the initialization and
configuration of different features of your application.
• BundleConfig.cs – This contains all of the configuration for minifying and
compressing your JavaScript and CSS files into one file.
• FilterConfig.cs – Registers Global Filters.
• RouteConfig.cs – Configuration of your routes.
There are other xxxxConfig.cs files that are added when you apply other MVC-
related technologies (for example, WebAPI adds WebApiConfig.cs).
• Content – This folder is meant for all of your static content like
images and style sheets. It’s best to create folders for them like
“images” or “styles” or “css”.
Layout of an MVC project
17
• Controllers – The controllers folder is where we place the
controllers.
• Models – This folder contains your business models. It’s
better when you have these models in another project, but
for demo purposes, we’ll place them in here.
• Scripts – This is where your JavaScript scripts reside.
• Views – This parent folder contains all of your HTML “Views”
with each controller name as a folder. Each folder will
contain a number of cshtml files relating to the methods in
that folder’s controller. If we had a URL that looked like this:
http://www.xyzcompany.com/Products/List
we would have a Products folder with a List.cshtml file.
We would also know to look in the Controllers folder and
open the ProductsController.cs and look for the List
method.
Layout of an MVC project
18
• Views/Shared – The Shared folder is meant for any shared
cshtml files you need across the website.
• Global.asax – The Global.asax is meant for the initialization
of the web application. If you look inside the Global.asax,
you’ll notice that this is where the RouteConfig.cs,
BundleConfig.cs, and FilterConfig.cs are called when the
application runs.
• Web.Config – The web.config is where you place
configuration settings for your application. For new MVC
developers, it’s good to know that you can place settings
inside the <appsettings> tag and place connection strings
inside the <connectionstring> tag.
Now that you know where everything is located in your
project, we can move forward with what is the process
when an MVC application is initially called.
MVC App Execution
19
• Entry points to MVC:
• UrlRoutingModuleand MvcRouteHandler
• Request handling:
• Select appropriate controller
• Obtain a specific controller instance
• Call the controller’s Execute method
• Receive first request for the application
• Populating RouteTable
• Perform routing
• Create MVC Request handler
• Create controller
• Execute controller
MVC App Execution
20
• Invoke action
• Execute result
• ViewResult, RedirectToRouteResult, ContentResult,
FileResult, JsonResult, RedirectResult
Models
21
• Models are probably the easiest section to address first.
Models are the objects that define and store your data so
you can use them throughout the application.
• Models to be the equivalent of plain old CLR (Common
Language Runtime) objects, or POCO’s. A POCO is a plain
class that holds structured data.
• one simple POCO (or model) would be similar to:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public IEnumerable<Order> Orders { get; set;
}
Models
22
Your business Model may look something like this:
public class Customer
{ public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public IEnumerable<Order> Orders { get; set; }
public DateTime FirstMet { get; set; }
public int CalculateAge(DateTime endTime)
{ var age = endTime.Year - FirstMet.Year;
if (endTime < FirstMet.AddYears(age))
age--;
return age;
}
}

More Related Content

What's hot

What's hot (20)

MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Introduction to ASP.NET MVC 1.0
Introduction to ASP.NET MVC 1.0Introduction to ASP.NET MVC 1.0
Introduction to ASP.NET MVC 1.0
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
 
Mvc4
Mvc4Mvc4
Mvc4
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
 
MVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros DeveloperMVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros Developer
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
Mvc
MvcMvc
Mvc
 
Mvc summary
Mvc summaryMvc summary
Mvc summary
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Word press 01
Word press 01Word press 01
Word press 01
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 

Similar to Aspnetmvc 1

ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC Introduction
Sumit Chhabra
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
Jennie Gajjar
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdf
Lê Thưởng
 

Similar to Aspnetmvc 1 (20)

Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Mvc
MvcMvc
Mvc
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
 
ASP.Net | Sabin Saleem
ASP.Net | Sabin SaleemASP.Net | Sabin Saleem
ASP.Net | Sabin Saleem
 
ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC Introduction
 
Aspnet mvc
Aspnet mvcAspnet mvc
Aspnet mvc
 
CG_CS25010_Lecture
CG_CS25010_LectureCG_CS25010_Lecture
CG_CS25010_Lecture
 
Session 1
Session 1Session 1
Session 1
 
Mvc Brief Overview
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overview
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdf
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Sitecore mvc
Sitecore mvcSitecore mvc
Sitecore mvc
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 

More from Fajar Baskoro

Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
Fajar Baskoro
 

More from Fajar Baskoro (20)

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptx
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarter
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUS
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptx
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptx
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptx
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi Kaltim
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolah
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remaja
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
 
epl1.pdf
epl1.pdfepl1.pdf
epl1.pdf
 
user.docx
user.docxuser.docx
user.docx
 
Dtmart.pptx
Dtmart.pptxDtmart.pptx
Dtmart.pptx
 
DualTrack-2023.pptx
DualTrack-2023.pptxDualTrack-2023.pptx
DualTrack-2023.pptx
 
BADGE.pptx
BADGE.pptxBADGE.pptx
BADGE.pptx
 
womenatwork.pdf
womenatwork.pdfwomenatwork.pdf
womenatwork.pdf
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Aspnetmvc 1

  • 2. MVC •NET Framework – A technology introduced in 2002 which includes the ability to create executables, web applications, and services using C# (pronounced see-sharp), Visual Basic, and F#. •ASP.NET – An open-source server-side web application framework which is a subset of Microsoft’s .NET framework. Their first iteration of ASP.NET included a technology called Web Forms. •ASP.NET WebForms – (2002 – current) A proprietary technique developed by Microsoft to manage state and form data across multiple pages. 2
  • 3. MVC •ASP.NET MVC is Microsoft’s framework for developing fast web applications using their .NET platform with either the C# or VB.NET language. •MVC is an acronym that stands for: • (M)odel – Objects that hold your data. • (V)iew – Views that are presented to your users, usually HTML pages or pieces of HTML. • (C)ontroller – Controllers are what orchestrates the retrieving and saving of data, populating models, and receiving data from the users. 3
  • 4. MVC •An alternative to ASP .NET Web Forms •Presentation framework • Lightweight • Highly testable •Integrated with the existing ASP .NET features: • Master pages • Membership-Based Authentication 4
  • 5. ASP .NET MVC Framework Components • Models • Business/domain logic • Model objects, retrieve and store model state in a persistent storage (database). • Views • Display application’s UI • UI created from the model data • Controllers • Handle user input and interaction • Work with model • Select a view for rendering UI 5
  • 6. Advantages of MVC •Advantages: • Easier to manage complexity (divide and conquer) • It does not use server forms and view state • Front Controller pattern (rich routing) • Better support for test-driven development • Ideal for distributed and large teams • High degree of control over the application behavior 6
  • 7. Advantages of MVC ASP.NET MVC has a separation of concerns. Separation of concerns means that your business logic is not contained in a View or controller. The business logic should be found in the models of your application. This makes web development even easier because it allows you to focus on integrating your business rules into reusable models. 7
  • 8. Advantages of MVC ASP.NET MVC provides testability out of the box. Another selling point is that ASP.NET MVC allows you to test every single one of your components, thereby making your code almost bulletproof. The more unit tests you provide for your application, the more durable your application will become. 8
  • 9. Advantages of MVC ASP.NET MVC has a smaller “View” footprint. With WebForms, there is a server variable called ViewState that tracks all of the controls on a page. If you have a ton of controls on your WebForm, the ViewState can grow to become an issue. ASP.NET MVC doesn’t have a ViewState, thus making the View lean and mean. 9
  • 10. Advantages of MVC ASP.NET MVC has more control over HTML. Since server-side controls aren’t used, the View can be as small as you want it to be. It provides a better granularity and control over how you want your pages rendered in the browser. 10
  • 11. ASP .NET MVC Features •Separation of application tasks • Input logic, business logic, UI logic •Support for test-driven development • Unit testing • No need to start app server •Extensible and pluggable framework • Components easily replaceable or customized(view engine, URL routing, data serialization,…) 11
  • 12. ASP .NET MVC App Structure •URLs mapped to controller classes •Controller • handles requests, • executes appropriate logic and • calls a View to generate HTML response •URL routing • ASP .NET routing engine (flexible mapping) • Support for defining customized routing rules • Automatic passing/parsing of parameters 12
  • 13. ASP .NET MVC App Structure •No Postbackinteraction! •All user interactions routed to a controller •No view state and page lifecycle events 13
  • 14. Layout of an MVC project When you create a new MVC project, your solution should have the following structure in your Solution Explorer. 14
  • 15. Layout of an MVC project 15
  • 16. Layout of an MVC project 16 • App_Data – While I don’t use this folder often, it’s meant to hold data for your application (just as the name says). A couple of examples would include a portable database (like SQL Server Compact Edition) or any kind of data files (XML, JSON, etc.). I prefer to use SQL Server. • App_Start – The App_Start folder contains the initialization and configuration of different features of your application. • BundleConfig.cs – This contains all of the configuration for minifying and compressing your JavaScript and CSS files into one file. • FilterConfig.cs – Registers Global Filters. • RouteConfig.cs – Configuration of your routes. There are other xxxxConfig.cs files that are added when you apply other MVC- related technologies (for example, WebAPI adds WebApiConfig.cs). • Content – This folder is meant for all of your static content like images and style sheets. It’s best to create folders for them like “images” or “styles” or “css”.
  • 17. Layout of an MVC project 17 • Controllers – The controllers folder is where we place the controllers. • Models – This folder contains your business models. It’s better when you have these models in another project, but for demo purposes, we’ll place them in here. • Scripts – This is where your JavaScript scripts reside. • Views – This parent folder contains all of your HTML “Views” with each controller name as a folder. Each folder will contain a number of cshtml files relating to the methods in that folder’s controller. If we had a URL that looked like this: http://www.xyzcompany.com/Products/List we would have a Products folder with a List.cshtml file. We would also know to look in the Controllers folder and open the ProductsController.cs and look for the List method.
  • 18. Layout of an MVC project 18 • Views/Shared – The Shared folder is meant for any shared cshtml files you need across the website. • Global.asax – The Global.asax is meant for the initialization of the web application. If you look inside the Global.asax, you’ll notice that this is where the RouteConfig.cs, BundleConfig.cs, and FilterConfig.cs are called when the application runs. • Web.Config – The web.config is where you place configuration settings for your application. For new MVC developers, it’s good to know that you can place settings inside the <appsettings> tag and place connection strings inside the <connectionstring> tag. Now that you know where everything is located in your project, we can move forward with what is the process when an MVC application is initially called.
  • 19. MVC App Execution 19 • Entry points to MVC: • UrlRoutingModuleand MvcRouteHandler • Request handling: • Select appropriate controller • Obtain a specific controller instance • Call the controller’s Execute method • Receive first request for the application • Populating RouteTable • Perform routing • Create MVC Request handler • Create controller • Execute controller
  • 20. MVC App Execution 20 • Invoke action • Execute result • ViewResult, RedirectToRouteResult, ContentResult, FileResult, JsonResult, RedirectResult
  • 21. Models 21 • Models are probably the easiest section to address first. Models are the objects that define and store your data so you can use them throughout the application. • Models to be the equivalent of plain old CLR (Common Language Runtime) objects, or POCO’s. A POCO is a plain class that holds structured data. • one simple POCO (or model) would be similar to: public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public string Company { get; set; } public IEnumerable<Order> Orders { get; set; }
  • 22. Models 22 Your business Model may look something like this: public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public string Company { get; set; } public IEnumerable<Order> Orders { get; set; } public DateTime FirstMet { get; set; } public int CalculateAge(DateTime endTime) { var age = endTime.Year - FirstMet.Year; if (endTime < FirstMet.AddYears(age)) age--; return age; } }