14
Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

Embed Size (px)

Citation preview

Page 1: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

Introduction to ASP.NET MVC

Chapter 1

ASP.NET MVC Development

Page 2: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

2

Contents

1. The case for ASP.NET MVC

2. Tooling up

Page 3: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

3

1. The Case for ASP.NET MVC

What is ASP.NET MVC? ASP.NET Web Forms – issues Web development – state of play ASP.NET MVC architecture ASP.NET MVC benefits ASP.NET Web Forms or MVC?

Page 4: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

4

What is ASP.NET MVC?

ASP.NET MVC is a web development platform from Microsoft• A significant evolution for web developers using the

Microsoft platform

ASP.NET MVC emphasises the best of the ASP.NET platform and agile development:• Clean architecture• Design patterns• Testability

Page 5: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

5

ASP.NET Web Forms – Issues

Traditional ASP.NET Web Forms were a great step forward when they first emerged• Much better than classic Active Server Pages (ASP)• Simple, especially for relatively small applications

However, there are some significant issues with ASP.NET Web Forms• ViewState transmission can be onerous• The ASP.NET page life cycle is complicated and subtle• The ASP.NET code-behind model encourages developers to

mix presentation logic and application logic• Web Forms attempt to encapsulate the intricacies of HTML

and HTTP, but this can sometimes be an obstacle• It's difficult to automate unit testing for ASP.NET Web

Forms

Page 6: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

6

Web Development – State of Play

Key features of Web development today:• Ajax• Web standards• REST (Representational State Transfer)• Agile and test-driven development

Page 7: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

7

ASP.NET MVC Architecture

The controller is probably the most interesting player• Processes user input

Works with the model to handle the request• Manages application logic

E.g. navigating a multi-step process, authentication, etc.• Prepares the data to be displayed

This is known as "view data" in ASP.NET MVC

View

HTTP Request

Response

HTML

Controller Model

View data

Page 8: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

8

ASP.NET MVC Benefits

Here are the key benefits of ASP.NET MVC:• Model-View-Controller architecture• Extensibility (ASP.NET MVC components are pluggable) • Reusable and consistent model classes• Testability• Flexible routing system• Tight control over HTML (standards-compliant)• Leverages strengths of the ASP.NET platform• Simplified JavaScript/Ajax integration

Page 9: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

9

ASP.NET Web Forms or MVC?

ASP.NET Web Forms is still appropriate for:• Small Web applications

MVC would be overkill• Simple Intranet-style Web applications

Fast networks, so you don't care about ViewState transmission overheads

• Quick-to-market apps Maybe you don't really care about unit testing or long-term

maintenance• Web apps where you have a lot of corporate data

Where you just want to display the data in data grids• Scenarios where the drag-and-drop simplicity of Web

Forms outweighs its weaknesses

A word about migration…• You can mix ASP.NET WebForms and MVC in the same Web

app• Allows you to migrate WebForms to MVC piecemeal, if you

want to

Page 10: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

10

2. Tooling Up

Core development tools MVC4 Downloading and installing MVC 4

Page 11: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

11

Core Development Tools

The following tools include ASP.NET MVC by default:• Visual Studio 2010 (any edition) • Visual Web Developer 2010 Express (free)

The following tools don't include ASP.NET MVC by default (you must download ASP.NET MVC separately from http://www.asp.net/mvc/)• Visual Studio 2008 with SP1 (any edition) • Visual Web Developer 2008 Express with SP1 (free)

Page 12: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

12

MVC4

ASP.NET MVC 4 builds on ASP.NET MVC 1, 2, and 3• Adds features to simplify code and support deeper

extensibility• Installs side-by-side with ASP.NET MVC 2

Key new features:• Expressive views, including the new Razor view engine • Internet and Intranet project templates• HTML 5 support• Extensible scaffolding with MvcScaffold integration• Hooks for Dependency Injection and global action filters • JavaScript and Ajax improvements• Model validation improvements• Controller improvements• Page caching and data caching

Page 13: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

13

Downloading and Installing MVC 4

Download available from MVC 4 home page• http://www.asp.net/mvc/mvc4

We'll install via installer executable• C:\AspNetMvc4\Products\

AspNetMVC4ToolsUpdateSetup.exe

Effect:• Adds new ASP.NET MVC 4 project templates• Extends existing APIs, adds new APIs

Page 14: Introduction to ASP.NET MVC Chapter 1 ASP.NET MVC Development

14

Summary

The case for ASP.NET MVC Tooling up