Book description
Top-selling MVC book from a top team at Microsoft—now fully updated!
ASP.NET MVC 2.0 is now available and shipping with Visual Studio 2010 and .NET 4. A new update to Microsoft's Model-View-Controller technologies, MVC 2 enables developers to build dynamic, data-driven Web sites. Professional ASP.NET MVC 2 shows you step-by-step how to use MVC 2. You'll learn both the theory behind MVC 2, as well as walk through practical tutorials, where you'll create a real-world application. Topics include transitioning from ASP.NET development, as well as an overview of related tools and technologies, including LINQ, jQuery, and REST.
This book is divided into two very broad sections, each comprising several chapters.
The first half of the book is concerned with introducing the MVC pattern and how ASP.NET MVC 2 implements that pattern.
Chapter 1 "NerdDinner" uses a small but complete application to walk you through how to build an ASP.NET MVC 2 application and some of the core concepts behind ASP.NET 2 MVC.
Chapter 2 "Model-View-Controller and ASP.NET" starts off with a description of the Model-View-Controller pattern, explaining the basic concepts of the pattern and providing a bit of its history. The chapter goes on to describe the state of the MVC pattern on the web today as it is implemented by various frameworks, such as ASP.NET MVC 2.
Chapter 3 "ASP.NET > ASP.NET MVC" then covers the ways that ASP.NET MVC is different from ASP.NET Web Forms.
Chapter 4 "Routes and URLs" digs deep into routing to describe the role that URLs play in your application and how routing figures into that. It also differentiates routing from URL rewriting and covers a bit on extending routing and writing unit tests for routes.
Chapter 5 "Controllers" takes a look at controllers and controller actions-what they are, and how to write them. It also covers action results, which are returned by controller actions and what they are used for.
Chapters 6 "Views" and 7 "Ajax" cover views and view engines, and then add a little flavor on top by examining the role that AJAX plays in your views.
The second half of the book focuses entirely on advanced techniques and extending the framework.
Chapter 8 "Filters" goes into detail on action filters, which provide an extensibility point for adding cross-cutting behaviors to action methods.
Chapter 9 "Securing Your Application" covers security and good practices for building a secure application.
Chapter 10 "Test Driven Development with ASP.NET MVC" provides a brief introduction to Test Driven Development (TDD) as it applies to ASP.NET MVC.
Chapter 11 "Testable Design Patterns" shows you real-world patterns and practices for building applications that are testable.
Chapter 12 "The Best of Both Worlds: Web Forms and MVC Together" discusses how Web Forms and MVC work together.
Chapter 13 "What's New in ASP.NET MVC 2" covers what's new in MVC 2.
This book is for web developers who are looking to add more complete testing to their web sites, and who are perhaps ready for "something different."
In some places, we assume that you're somewhat familiar with ASP.NET WebForms, at least peripherally. There are a lot of ASP.NET WebForms developers out there who are interested in ASP.NET MVC so there are a number of places in this book where we contrast the two technologies. Even if you're not already an ASP.NET developer, you might still find these sections interesting for context, as well as for your own edification as ASP.NET MVC may not be the web technology that you're looking for.
Table of contents
- Copyright
- ABOUT THE AUTHORS
- ABOUT THE TECHNICAL EDITORS
- CREDITS
- ACKNOWLEDGMENTS
- FOREWORD
- INTRODUCTION
-
1. NerdDinner
- 1.1. FILE NEW PROJECT
- 1.2. CREATING THE DATABASE
-
1.3. BUILDING THE MODEL
- 1.3.1. Entity Framework
- 1.3.2. Adding Entity Framework Classes to Our Project
- 1.3.3. Creating Data Model Classes with Entity Framework
- 1.3.4. NerdDinnerEntities Class
- 1.3.5. Creating a DinnerRepository Class
- 1.3.6. Retrieving, Updating, Inserting, and Deleting Using the DinnerRepository Class
- 1.3.7. Integrating Validation and Business Rule Logic with Model Classes
-
1.4. CONTROLLERS AND VIEWS
- 1.4.1. Adding a DinnersController Controller
- 1.4.2. Adding Index and Details Action Methods to the DinnersController Class
- 1.4.3. Understanding ASP.NET MVC Routing
- 1.4.4. Using the DinnerRepository from Our DinnersController
- 1.4.5. Using Views with Our Controller
- 1.4.6. Implementing the "NotFound" View Template
- 1.4.7. Implementing the "Details" View Template
- 1.4.8. Implementing the "Index" View Template
- 1.4.9. Convention-Based Naming and the \Views Directory Structure
-
1.5. CREATE, UPDATE, DELETE FORM SCENARIOS
- 1.5.1. URLs Handled by DinnersController
- 1.5.2. Implementing the HTTP-GET Edit Action Method
- 1.5.3. Html.BeginForm and Html.TextBoxFor Html Helper Methods
- 1.5.4. Implementing the HTTP-POST Edit Action Method
- 1.5.5. Handling Edit Errors
- 1.5.6. Understanding ModelState and the Validation HTML Helper Methods
- 1.5.7. Complete Edit Action Method Implementations
- 1.5.8. Implementing the HTTP-GET Create Action Method
- 1.5.9. Implementing the HTTP-POST Create Action Method
- 1.5.10. Implementing the HTTP-GET Delete Action Method
- 1.5.11. Implementing the HTTP-POST Delete Action Method
- 1.5.12. Model Binding Security
- 1.5.13. CRUD Wrap-Up
- 1.6. VIEWDATA AND VIEWMODEL
- 1.7. PARTIALS AND MASTER PAGES
- 1.8. PAGING SUPPORT
-
1.9. AUTHENTICATION AND AUTHORIZATION
- 1.9.1. Understanding Authentication and Authorization
- 1.9.2. Forms Authentication and the AccountController
- 1.9.3. Authorizing the /Dinners/Create URL Using the [Authorize] Filter
- 1.9.4. Using the User.Identity.Name Property When Creating Dinners
- 1.9.5. Using the User.Identity.Name Property When Editing Dinners
- 1.9.6. Showing/Hiding Edit and Delete Links
- 1.10. AJAX ENABLING RSVPS ACCEPTS
-
1.11. INTEGRATING AN AJAX MAP
- 1.11.1. Creating a Map Partial View
- 1.11.2. Creating a Map.js Utility Library
- 1.11.3. Integrating the Map with Create and Edit Forms
- 1.11.4. Integrating the Map with the Details View
- 1.11.5. Implementing Location Search in Our Database and Repository
- 1.11.6. Implementing a JSON-Based AJAX Search Action Method
- 1.11.7. Calling the JSON-Based AJAX Method Using jQuery
-
1.12. UNIT TESTING
- 1.12.1. Why Unit Test?
- 1.12.2. NerdDinner.Tests Project
- 1.12.3. Creating Unit Tests for Our Dinner Model Class
- 1.12.4. Running Tests
- 1.12.5. Creating DinnersController Unit Tests
- 1.12.6. Dependency Injection
- 1.12.7. Extracting an IDinnerRepository Interface
- 1.12.8. Updating DinnersController to Support Constructor Injection
- 1.12.9. Creating the FakeDinnerRepository Class
- 1.12.10. Using the FakeDinnerRepository with Unit Tests
- 1.12.11. Creating Edit Action Unit Tests
- 1.12.12. Mocking the User.Identity.Name Property
- 1.12.13. Testing UpdateModel Scenarios
- 1.12.14. Testing Wrap-Up
- 1.13. NERDDINNER WRAP-UP
- 2. Model-View-Controller and ASP.NET
- 3. ASP.NET > ASP.NET MVC
-
4. Routes and URLs
- 4.1. INTRODUCTION TO ROUTING
- 4.2. UNDER THE HOOD: HOW ROUTES TIE YOUR URL TO AN ACTION
- 4.3. ADVANCED ROUTING WITH CUSTOM CONSTRAINTS
- 4.4. ROUTE EXTENSIBILITY
- 4.5. USING ROUTING WITH WEB FORMS
- 4.6. SUMMARY
-
5. Controllers
- 5.1. HISTORY OF THE CONTROLLER
- 5.2. DEFINING THE CONTROLLER: THE ICONTROLLER INTERFACE
- 5.3. THE CONTROLLERBASE ABSTRACT BASE CLASS
- 5.4. THE CONTROLLER CLASS AND ACTIONS
- 5.5. THE ACTIONRESULT
-
5.6. ACTION INVOKER
- 5.6.1. How an Action Is Mapped to a Method
- 5.6.2. Mapping Parameters
- 5.6.3. Invoking Actions
-
5.6.4. Using Asynchronous Controller Actions
- 5.6.4.1. Choosing Synchronous versus Asynchronous Pipelines
- 5.6.4.2. Writing Asynchronous Action Methods
- 5.6.4.3. The MVC Pattern for Asynchronous Actions
- 5.6.4.4. Performing Multiple Parallel Operations
- 5.6.4.5. Using Filters with Asynchronous Controller Actions
- 5.6.4.6. Timeouts
- 5.6.4.7. Additional Considerations for Asynchronous Methods
- 5.6.5. Passing Data to Actions: The Model Binders
- 5.6.6. A Word about User Input
- 5.7. SUMMARY
-
6. Views
- 6.1. WHAT A VIEW DOES
- 6.2. WHAT A VIEW SHOULDN'T DO
- 6.3. SPECIFYING A VIEW
- 6.4. STRONGLY TYPED VIEWS
- 6.5. VIEWMODELS
-
6.6. HTML HELPER METHODS
- 6.6.1. HtmlHelper Class and Extension Methods
-
6.6.2. Using the HTML Helpers
- 6.6.2.1. Strongly Typed HTML Helpers
- 6.6.2.2. Html.Encode
- 6.6.2.3. Html.TextBox
- 6.6.2.4. Html.ActionLink and Html.RouteLink
- 6.6.2.5. Html.BeginForm
- 6.6.2.6. Html.Hidden
- 6.6.2.7. Html.DropDownList and Html.ListBox
- 6.6.2.8. Html.Password
- 6.6.2.9. Html.RadioButton
- 6.6.2.10. Html.Partial and Html.RenderPartial
- 6.6.2.11. Html.Action and Html.RenderAction
- 6.6.2.12. Html.TextArea
- 6.6.2.13. Html.ValidationMessage
- 6.6.2.14. Html.ValidationSummary
- 6.6.3. HTML Template Customization
- 6.7. THE VIEW ENGINE
- 6.8. NEW VIEW ENGINE OR NEW ACTIONRESULT?
- 6.9. SUMMARY
-
7. AJAX
- 7.1. WHEN AJAX IS COOL
- 7.2. WHEN IT'S NOT
-
7.3. AJAX EXAMPLES
- 7.3.1. Handling Disabled Scripting
- 7.3.2. Using Partials for Rendering
- 7.3.3. Some Things You May Not Know about Microsoft ASP.NET Ajax
- 7.3.4. How It Works
- 7.3.5. Updating an HTML Element When Submitting a Form
- 7.3.6. The AutoComplete TextBox
- 7.3.7. Implementing AutoComplete with Microsoft ASP.NET Ajax
- 7.3.8. Filtering Data with a Selectbox
- 7.3.9. The Modal Pop-Up with jQuery
- 7.3.10. The Modal Pop-Up Code
- 7.3.11. The Rating Control
- 7.4. SUMMARY
-
8. Filters
- 8.1. FILTERS INCLUDED WITH ASP.NET MVC
- 8.2. WRITING A CUSTOM ACTION FILTER
- 8.3. WRITING A CUSTOM AUTHORIZATION FILTER
- 8.4. WRITING A CUSTOM EXCEPTION FILTER
- 8.5. FILTER ORDERING
- 8.6. FILTER NAMING
- 8.7. SUMMARY
-
9. Securing Your Application
- 9.1. THIS IS A WAR
- 9.2. WEAPONS
- 9.3. THREAT: CROSS-SITE SCRIPTING (XSS)
- 9.4. THREAT: CROSS-SITE REQUEST FORGERY
- 9.5. THREAT: COOKIE STEALING
- 9.6. THREAT: OVER-POSTING
- 9.7. KEEPING YOUR PANTS UP: PROPER ERROR REPORTING AND THE STACK TRACE
- 9.8. SECURING YOUR CONTROLLERS, NOT YOUR ROUTES
- 9.9. SUMMARY: IT'S UP TO YOU
- 10. Test Driven Development with ASP.NET MVC
- 11. Testable Design Patterns
-
12. Best of Both Worlds: Web Forms and MVC Together
- 12.1. HOW IS IT POSSIBLE?
- 12.2. INCLUDING MVC IN EXISTING WEB FORMS APPLICATIONS
- 12.3. ADDING WEB FORMS TO AN EXISTING ASP.NET MVC APPLICATION
- 12.4. SHARING DATA BETWEEN WEB FORMS AND MVC
- 12.5. MIGRATING FROM WEB FORMS TO MVC
- 12.6. SUMMARY
-
13. What's New in ASP.NET MVC 2
- 13.1. SECURITY
- 13.2. PRODUCTIVITY
- 13.3. PERFORMANCE: ASYNCHRONOUS CONTROLLER ACTIONS
- 13.4. MISCELLANEOUS
- 13.5. SUMMARY
Product information
- Title: Professional ASP.NET MVC 2
- Author(s):
- Release date: June 2010
- Publisher(s): Wrox
- ISBN: 9780470643181
You might also like
book
Professional ASP.NET MVC 3
New edition of the top book on MVC from the top ASP.NET experts at Microsoft! MVC …
book
Professional ASP.NET MVC 4
An outstanding author team presents the ultimate Wrox guide to ASP.NET MVC 4 Microsoft insiders join …
book
Beginning ASP.NET MVC 4
By now you'll have heard of ASP.NET MVC. This exciting new approach to developing ASP.NET web …
book
ASP.NET MVC 4 in Action
ASP.NET MVC 4 in Action is a fast-paced tutorial designed to introduce ASP.NET MVC to .NET …