Table of Contents

Introduction

How This Book Is Organized

What You Should Know Before Reading This Book

What Software Do You Need?

Where Do You Download the Code Samples?

If You Like This Book

Part I. Building ASP.NET MVC Applications

1. An Introduction to ASP.NET MVC

A Story with a Moral

What Is Good Software?

Avoiding Code Smells

Software Design Principles

Software Design Patterns

Writing Unit Tests for Your Code

Test-Driven Development

Short-Term Pain, Long-Term Gain

What Is ASP.NET MVC?

ASP.NET MVC Is Part of the ASP.NET Framework

The Origins of MVC

The Architecture of an ASP.NET MVC Application

Understanding the Sample ASP.NET MVC Application

ASP.NET MVC Folder Conventions

Running the Sample ASP.NET MVC Application

2. Building a Simple ASP.NET MVC Application

Starting with a Blank Slate

Creating the Database

Creating the Model

Creating the Controller

Creating the Views

Adding the Index View

Adding the Create View

3. Understanding Controllers and Actions

Creating a Controller

Returning Action Results

Returning a View Result

Returning a Redirect Result

Returning a Content Result

Returning a JSON Result

Returning a File Result

Controlling How Actions Are Invoked

Using AcceptVerbs

Using ActionName

Using ActionMethodSelector

Handling Unknown Actions

Testing Controllers and Actions

4. Understanding Views

Creating a View

Using View Data

Typed and Untyped Views

Creating Strongly Typed Views

Preventing JavaScript Injection Attacks

Using Alternative View Engines

Creating a Custom View Engine

Testing Views

Test the View Result

Test HTML Helpers

Test a Custom View Engine

5. Understanding Models

Creating a Data Model

Creating a Data Model with the Microsoft Entity Framework

Listing Records

Getting a Single Record

Creating Records

Editing Records

Deleting Records

Using the Repository Pattern

Creating a Product Repository

Using the Dependency Injection Pattern

Creating a Generic Repository

Using the Generic Repository with the Entity Framework

Using the Generic Repository with LINQ to SQL

Extending the Generic Repository

Testing Data Access

Testing with a Mock Repository

Testing with a Fake Generic Repository

6. Understanding HTML Helpers

Using the Standard HTML Helpers

Rendering Links

Rendering Image Links

Rendering Form Elements

Rendering a Form

Rendering a Drop-Down List

Encoding HTML Content

Using Antiforgery Tokens

Creating Custom HTML Helpers

Using the TagBuilder Class

Using the HtmlTextWriter Class

Creating a DataGrid Helper

Adding Sorting to the DataGrid Helper

Adding Paging to the DataGrid Helper

Testing Helpers

7. Understanding Model Binders and Action Filters

Understanding Model Binders

Using the Default Model Binder

Binding to Complex Classes

Using the Bind Attribute

Using Bind with Classes

Using Prefixes When Binding

Using the Form Collection Model Binder

Using the HTTP Posted File Base Model Binder

Creating a Custom Model Binder

Understanding Action Filters

Creating a Log Action Filter

8. Validating Form Data

Understanding Model State

Understanding the Validation Helpers

Styling Validation Error Messages

Prebinding and Postbinding Validation

Validating with a Service Layer

Validating with the IDataErrorInfo Interface

Testing Validation

9. Understanding Routing

Using the Default Route

Debugging Routes

Creating Custom Routes

Creating Route Constraints

Using Regular Expression Constraints

Using the HttpMethod Constraint

Creating an Authenticated Constraint

Creating a NotEqual Constraint

Using Catch-All Routes

Testing Routes

Using the MvcFakes and RouteDebugger Assemblies

Testing If a URL Matches a Route

Testing Routes with Constraints

10. Understanding View Master Pages and View User Controls

Understanding View Master Pages

Creating a View Master Page

Creating a View Content Page

Setting the Master Page from the Controller

Setting the Master Page Title

Nested Master Pages

Passing View Data to Master Pages

Understanding View User Controls

Passing View Data to User Controls

Using a View User Control as a Template

11. Better Performance with Caching

Using the OutputCache Attribute

Don’t Cache Private Data

What Gets Cached?

Setting the Cache Location

Varying the Output Cache by Parameter

Varying the Output Cache

Removing Items from the Output Cache

Using Cache Profiles

Using the Cache API

Using the HttpCachePolicy Class

Using the Cache Class

Testing the Cache

Testing the OutputCache Attribute

Testing Adding Data to the Cache

12. Authenticating Users

Creating Users and Roles

Using the Web Site Administration Tool

Using the Account Controller

Authorizing Users

Using the Authorize Attribute

Using the User Property

Configuring Membership

Configuring the Membership Database

Configuring Membership Settings

Using the Membership and Role Manager API

Using Windows Authentication

Configuring Windows Authentication

Authenticating Windows Users and Groups

Testing Authorization

Testing for the Authorize Attribute

Testing with the User Model Binder

13. Deploying ASP.NET MVC Applications

Configuring IIS for ASP.NET MVC

Integrated Versus Classic Mode

Using ASP.NET MVC with Older Versions of IIS

Adding Extensions to the Route Table

Hosted Server

Creating a Wildcard Script Map

Mixing ASP.NET Web Forms and ASP.NET MVC

Modifying the Visual Studio Project File

Adding the Required Assemblies

Modifying the Web Configuration File

Modify the Global.asax File

Using Web Forms and MVC

Bin Deploying an ASP.NET MVC Application

14. Working with Ajax

Using the Ajax Helpers

Debugging Ajax

Posting a Form Asynchronously

Displaying Progress

Updating Content After Posting

Performing Validation

Providing Downlevel Browser Support

Retrieving Content Asynchronously

Highlighting the Selected Link

Creating a Delete Link

Providing Downlevel Browser Support

Using the AcceptAjax Attribute

15. Using jQuery

Overview of jQuery

Including the jQuery Library

jQuery and Visual Studio Intellisense

Using jQuery Selectors

Adding Event Handlers

Using jQuery Animations

jQuery and Ajax

Using jQuery Plug-Ins

Part II. Walkthrough: Building the Unleashed Blog Application

16. Overview of the Application

What Is Test-Driven Development?

Why Do Test-Driven Development?

The KISS and YAGNI Principles

Waterfall Versus Evolutionary Design

TDD Tests Are Not Unit Tests

Tests Flow from User Stories

Unit Testing Frameworks

Bibliography of Test-Driven Development

17. Database Access

Creating the Unleashed Blog Project

Creating Our First Test

Creating New Blog Entries

Refactoring to Use the Repository Pattern

Creating a Fake Blog Repository

Creating an Entity Framework Repository

Creating the Database Objects

Creating the Entity Framework Data Model

Creating the Entity Framework Blog Repository

Using the Entity Framework Repository

18. Creating the Routes

Creating the Controller Tests

Creating the Route Tests

Creating the Archive Routes

Trying Out the Archive Controller

19. Adding Validation

Performing Validation in the Simplest Possible Way

Refactoring the Test Code

Validating the Length of a Property

A Web Browser Sanity Check

Refactoring to Use a Service Layer

Adding Business Rules

20. Paging, Views, and Ajax

Adding Paging Support

Adding the Views

Adding Ajax Support

21. Adding Comments

Implementing Comments

Adding Comments to the Database

Displaying Comments and Comment Counts

Part III. Appendixes

A. C# and VB.NET Language Features

Type Inference

Object Initializers

Anonymous Types

Nullable Types

Extension Methods

Generics

Lambda Expressions

LINQ

B. Using a Unit Testing Framework

Using Visual Studio Unit Test

Understanding the Test Attributes

Using Assertions

Running the Tests

Limiting Visual Studio Test Results

Using NUnit

Creating an NUnit Unit Test Project

Creating a Test

Running Tests

C. Using a Mock Object Framework

Understanding the Terminology

Installing Moq

Using Moq to Create a Class from an Interface

Returning Fake Values

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.168.203