0% found this document useful (0 votes)
269 views

Introduction To ASP - NET MVC

Understand the basics of the Model-View-Controller pattern and explore the differences between ASP.NET Web forms and MVC applications.

Uploaded by

Craig
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
269 views

Introduction To ASP - NET MVC

Understand the basics of the Model-View-Controller pattern and explore the differences between ASP.NET Web forms and MVC applications.

Uploaded by

Craig
Copyright
© © All Rights Reserved
You are on page 1/ 19

Introduction to ASP.

NET MVC

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Objectives
Understand the basics of the Model-ViewController pattern Explore the differences between ASP.NET Web forms and MVC applications Build a sample MVC application and explore its structure

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Agenda
The Model-View-Controller Pattern Differences Between MVC and Web Forms Applications Building a Simple MVC Application with Visual Studio

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

The Model-View-Controller Pattern


ASP.NET MVC is a revolutionary way to develop Web applications
Built on Model-View-Controller pattern Separation of concerns Invented in 1978 by Trygve Reenskaug Very popular in Web development frameworks

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

The MVC Architecture


Three primary components
Model View Controller

User interaction with application


1. Interacts with Web page 2. Controller handles request 3. Notifies model of changes 4. Controller selects a view 5. Await new user interaction
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company

Anatomy of a Request
HTTP Request HTML Response

View

Controller

Model

Optional Persistent Storage

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

ASP.NET MVC
Microsofts newest Web development framework
Easy to implement design principles and patterns Integral part of ASP.NET

First implementation by Scott Guthrie Built using core ASP.NET features

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Differences Between MVC and Web Forms Applications


ASP.NET Web forms was revolutionary in its day
Rich infrastructure for Web version of desktop applications Abstracts limitations of HTTP Uses ViewState as a major feature Drag and drop development interface

Problems with Web forms


Little control over HTML ViewState can bloat Limited support for testing Complicated page lifecycle
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company

The Tenets of MVC


Separation of concerns Convention over configuration Keep it DRY: Dont Repeat Yourself Be helpful, but get out of my way

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC

Extensibility

ASP.NET has a provider model MVC has a more powerful pluggable model Options
Use the default component Extend the default component Replace the default component

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC


Blending of Concerns Web forms almost forces combination of view and controller False sense of separation from code behind files
Reality: close coupling

MVCs separation of concerns encourages good coding practices


Ideally suited to Web application development

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC

MVC Serves Methods, Not Files Huge difference File request: http://www.example.com/index.aspx?ID=5 Method request: http://www.example.com/Home/Details/5
Maps to Details action method Of Home controller Item ID of 5

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC


Testability Testing helps make applications more robust in the face of changes Unit test automates verification of a method Can use the test-driven development methodology Web forms make automated testing almost impossible

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC


Control over HTML Web forms server controls provide rich functionality
Produce unreadable, monolithic blocks of HTML

MVC gives you complete control over HTML

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Web Forms vs. MVC


Open Source MVC source code is available Liberal open source license: Microsoft Public License

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Building a Simple MVC Application with Visual Studio


Building MVC applications can be efficient, because:
Web forms often require fragmented code MVCs convention over configuration MVC tools in Visual Studio 2008 and 2010

Best of all worlds with MVC

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

MVC Project Templates


Includes one Visual Studio Project template
Available for VB and C#

Includes templates for three project types


Internet Application template
o

Basic but fully functional MVC application Same as Internet template, but uses Windows authentication Sets up project structure but no controllers or models

Intranet Application template


o

Empty template
o

Use whichever template you like


Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company

Upgrading from MVC 2 to 3


Can install MVC 3 side-by-side with MVC 1 and 2 When ready, upgrade to MVC 3 Process is manual
Change a GUID, copy files, change web.config, etc. Better to just create a new project and move stuff? Release notes cover the basic steps

Microsofts Eilon Lipton has an unsupported migration tool

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

Learn More!
This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn more about MVC on SlideShare:
Working with Controllers and Actions in MVC

Learn More @ http://www.learnnowonline.com


Copyright by Application Developers Training Company

You might also like