Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Coverpage
Titlepage
Copyright
Dedication
Contents at a Glance
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Part 1: Introducing ASP.NET MVC 4
Chapter 1: What’s the Big Idea?
A Brief History of Web Development
Traditional ASP.NET Web Forms
What Is Wrong with ASP.NET Web Forms?
Web Development Today
Web Standards and REST
Agile and Test-Driven Development
Ruby on Rails
Sinatra
Node.js
Key Benefits of ASP.NET MVC
MVC Architecture
Extensibility
Tight Control over HTML and HTTP
Testability
Powerful Routing System
Built on the Best Parts of the ASP.NET Platform
Modern API
ASP.NET MVC Is Open Source
Who Should Use ASP.NET MVC?
Comparisons with ASP.NET Web Forms
Migrating from Web Forms to MVC
Comparisons with Ruby on Rails
Comparisons with MonoRail
What’s New in ASP.NET MVC 4?
Summary
Chapter 2: Your First MVC Application
Preparing the Workstation
Creating a New ASP.NET MVC Project
Adding the First Controller
Understanding Routes
Rendering Web Pages
Creating and Rendering a View
Adding Dynamic Output
Creating a Simple Data-Entry Application
Setting the Scene
Designing a Data Model
Linking Action Methods
Building the Form
Handling Forms
Adding Validation
Completing the Example
Summary
Chapter 3: The MVC Pattern
The History of MVC
Understanding the MVC Pattern
Understanding the Domain Model
The ASP.NET Implementation of MVC
Comparing MVC to Other Patterns
Applying Domain-Driven Development
Modeling an Example Domain
Ubiquitous Language
Aggregates and Simplification
Defining Repositories
Building Loosely Coupled Components
Using Dependency Injection
An MVC-Specific DI Example
Using a Dependency Injection Container
Getting Started with Automated Testing
Understanding Unit Testing
Understanding Integration Testing
Summary
Chapter 4: Essential Language Features
Creating the Example Project
Using Automatically Implemented Properties
Using Object and Collection Initializers
Using Extension Methods
Applying Extension Methods to an Interface
Creating Filtering Extension Methods
Using Lambda Expressions
Using Automatic Type Inference
Using Anonymous Types
Performing Language Integrated Queries
Understanding Deferred LINQ Queries
Using Async Methods
Applying the async and await Keywords
Summary
Chapter 5: Working with Razor
Creating the Example Project
Defining the Model
Defining the Controller
Creating the View
Working with the Model Object
Working with Layouts
Creating the Layout
Applying a Layout
Using a View Start File
Demonstrating Shared Layouts
Using Razor Expressions
Inserting Data Values
Setting Attribute Values
Using Conditional Statements
Enumerating Arrays and Collections
Dealing with Namespaces
Summary
Chapter 6: Essential Tools for MVC
Creating the Example Project
Creating the Model Classes
Adding the Controller
Adding the View
Using Ninject
Understanding the Problem
Adding Ninject to the Visual Studio Project
Getting Started with Ninject
Setting up MVC Dependency Injection
Creating Chains of Dependency
Specifying Property and Constructor Parameter Values
Using Conditional Binding
Unit Testing with Visual Studio
Creating the Unit Test Project
Creating the Unit Tests
Running the Unit Tests (and Failing)
Implementing the Feature
Testing and Fixing the Code
Using Moq
Understanding the Problem
Adding Moq to the Visual Studio Project
Adding a Mock Object to a Unit Test
Creating a More Complex Mock Object
Summary
Chapter 7: SportsStore—A Real Application
Getting Started
Creating the Visual Studio Solution and Projects
Adding References
Setting Up the DI Container
Starting the Application
Starting the Domain Model
Creating an Abstract Repository
Making a Mock Repository
Displaying a List of Products
Adding a Controller
Adding the View
Setting the Default Route
Running the Application
Preparing a Database
Creating the Database
Defining the Database Schema
Adding Data to the Database
Creating the Entity Framework Context
Creating the Product Repository
Adding Pagination
Displaying Page Links
Improving the URLs
Styling the Content
Defining Common Content in the Layout
Adding CSS Styles
Creating a Partial View
Summary
Chapter 8: SportsStore: Navigation
Adding Navigation Controls
Filtering the Product List
Refining the URL Scheme
Building a Category Navigation Menu
Correcting the Page Count
Building the Shopping Cart
Defining the Cart Entity
Adding the Add to Cart Buttons
Implementing the Cart Controller
Displaying the Contents of the Cart
Summary
Chapter 9: SportsStore: Completing the Cart
Using Model Binding
Creating a Custom Model Binder
Completing the Cart
Removing Items from the Cart
Adding the Cart Summary
Submitting Orders
Extending the Domain Model
Adding the Checkout Process
Implementing the Order Processor
Registering the Implementation
Completing the Cart Controller
Displaying Validation Errors
Displaying a Summary Page
Summary
Chapter 10: SportsStore: Administration
Adding Catalog Management
Creating a CRUD Controller
Creating a New Layout
Implementing the List View
Editing Products
Creating New Products
Deleting Products
Summary
Chapter 11: SportsStore: Security & Finishing Touches
Securing the Administration Controller
Applying Authorization with Filters
Creating the Authentication Provider
Creating the Account Controller
Creating the View
Image Uploads
Extending the Database
Enhancing the Domain Model
Creating the Upload User Interface Elements
Saving Images to the Database
Implementing the GetImage Action Method
Displaying Product Images
Summary
Part 2: ASP.NET MVC 4 in Detail
Chapter 12: Overview of MVC Projects
Working with Visual Studio MVC Projects
Understanding MVC Conventions
Debugging MVC Applications
Creating the Project
Launching the Visual Studio Debugger
Causing the Visual Studio Debugger to Break
Using Edit and Continue
Summary
Chapter 13: URL Routing
Creating the Example Project
Introducing URL Patterns
Creating and Registering a Simple Route
Using the Simple Route
Defining Default Values
Using Static URL Segments
Defining Custom Segment Variables
Using Custom Variables as Action Method Parameters
Defining Optional URL Segments
Defining Variable-Length Routes
Prioritizing Controllers by Namespaces
Constraining Routes
Constraining a Route Using a Regular Expression
Constraining a Route to a Set of Specific Values
Constraining a Route Using HTTP Methods
Defining a Custom Constraint
Routing Requests for Disk Files
Configuring the Application Server
Defining Routes for Disk Files
Bypassing the Routing System
Summary
Chapter 14: Advanced Routing Features
Preparing the Example Project
Generating Outgoing URLs in Views
Using the Routing System to Generate an Outgoing URL
Targeting Other Controllers
Passing Extra Values
Specifying HTML Attributes
Generating Fully Qualified URLs in Links
Generating URLs (and Not Links)
Generating Outgoing URLs in Action Methods
Generating a URL from a Specific Route
Customizing the Routing System
Creating a Custom RouteBase Implementation
Creating a Custom Route Handler
Working with Areas
Creating an Area
Populating an Area
Resolving the Ambiguous Controller Issue
Generating Links to Actions in Areas
URL Schema Best Practices
Make Your URLs Clean and Human-Friendly
GET and POST: Pick the Right One
Summary
Chapter 15: Controllers and Actions
Introducing the Controller
Preparing the Example Project
Creating a Controller with IController
Creating a Controller by Deriving from the Controller Class
Receiving Input
Getting Data from Context Objects
Using Action Method Parameters
Producing Output
Understanding Action Results
Returning HTML by Rendering a View
Passing Data from an Action Method to a View
Performing Redirections
Returning Errors and HTTP Codes
Summary
Chapter 16: Filters
Using Filters
Introducing the Four Basic Types of Filters
Applying Filters to Controllers and Action Methods
Creating the Example Project
Using Authorization Filters
Applying the Custom Authorization Filter
Using the Built-in Authorization Filter
Using Exception Filters
Creating an Exception Filter
Applying the Exception Filter
Using a View to Respond to an Exception
Using the Built-In Exception Filter
Using Action Filters
Implementing the OnActionExecuting Method
Implementing the OnActionExecuted Method
Using Result Filters
Using the Built-In Action and Result Filter Class
Using Other Filter Features
Filtering Without Attributes
Using Global Filters
Ordering Filter Execution
Using the Built-in Filters
Using the RequireHttps Filter
Using the OutputCache Filter
Summary
Chapter 17: Controller Extensibility
Creating the Example Project
Creating a Custom Controller Factory
Dealing with the Fallback Controller
Instantiating Controller Classes
Implementing the Other Interface Methods
Registering a Custom Controller Factory
Working with the Built-In Controller Factory
Prioritizing Namespaces
Customizing DefaultControllerFactory Controller Instantiation
Creating a Custom Action Invoker
Using the Built-In Action Invoker
Using a Custom Action Name
Using Action Method Selection
Improving Performance with Specialized Controllers
Using Sessionless Controllers
Using Asynchronous Controllers
Summary
Chapter 18: Views
Creating a Custom View Engine
Creating the Example Project
Creating a Custom IView
Creating an IViewEngine Implementation
Registering a Custom View Engine
Testing the View Engine
Working with the Razor Engine
Creating the Example Project
Understanding Razor View Rendering
Configuring the View Search Locations
Adding Dynamic Content to a Razor View
Using Sections
Using Partial Views
Using Child Actions
Summary
Chapter 19: Helper Methods
Creating the Example Project
Creating Custom Helper Methods
Creating an Inline Helper Method
Creating an External Helper Method
Managing String Encoding in a Helper Method
Using the Built-In Form Helper Methods
Creating Form Elements
Specifying the Route Used by a Form
Using Input Helpers
Creating Select Elements
Summary
Chapter 20: Templated Helper Methods
Reviewing the Example Project
Using Templated Helper Methods
Generating Label and Display Elements
Using Whole-Model Template Helpers
Using Model Metadata
Using Metadata to Control Editing and Visibility
Using Metadata for Labels
Using Metadata for Data Values
Using Metadata to Select a Display Template
Applying Metadata to a Buddy Class
Working with Complex Type Properties
Customizing the Templated View Helper System
Creating a Custom Editor Template
Creating a Generic Template
Replacing the Built-in Templates
Summary
Chapter 21: URL and Ajax Helper Methods
Reviewing and Preparing the Example Project
Creating Basic Links and URLs
Using MVC Unobtrusive Ajax
Creating the Synchronous Form View
Preparing the Project for Unobtrusive Ajax
Creating an Unobtrusive Ajax Form
Preparing the Controller
Creating the Ajax Form
Understanding How Unobtrusive Ajax Works
Setting Ajax Options
Ensuring Graceful Degradation
Providing the User with Feedback While Making an Ajax Request
Prompting the User Before Making a Request
Creating Ajax Links
Ensuring Graceful Degradation for Links
Working with Ajax Callbacks
Working with JSON
Adding JSON Support to the Controller
Processing JSON in the Browser
Preparing Data for Encoding
Detecting Ajax Requests in the Action Method
Summary
Chapter 22: Model Binding
Preparing the Example Project
Understanding Model Binding
Using the Default Model Binder
Binding to Simple Types
Binding to Complex Types
Binding to Arrays and Collections
Manually Invoking Model Binding
Dealing with Binding Errors
Customizing the Model Binding System
Creating a Custom Value Provider
Creating a Custom Model Binder
Registering the Custom Model Binder
Summary
Chapter 23: Model Validation
Creating the Example Project
Explicitly Validating a Model
Displaying Validation Errors to the User
Displaying Validation Messages
Displaying Property-Level Validation Messages
Using Alternative Validation Techniques
Performing Validation in the Model Binder
Specifying Validation Rules Using Metadata
Defining Self-Validating Models
Performing Client-Side Validation
Enabling and Disabling Client-Side Validation
Using Client-Side Validation
Understanding How Client-Side Validation Works
Performing Remote Validation
Summary
Chapter 24: Bundles and Display Modes
Understanding the Default Script Libraries
Preparing the Example Application
Managing Scripts and Style Sheets
Profiling Script and Style Sheet Loading
Using Script and Style Bundles
Applying Bundles
Using the Scripts Section
Profiling the Changes
Targeting Mobile Devices
Taking Stock of the Application
Using Mobile Specific Layouts and Views
Creating Custom Display Modes
Summary
Chapter 25: Web API
Understanding the Web API
Creating the Web API Application
Creating the Model and Repository
Creating the Home Controller
Creating the View and the CSS
Creating the API Controller
Testing the API Controller
Understanding How the API Controller Works
Understanding API Controller Action Selection
Mapping HTTP Methods to Action Methods
Writing the JavaScript Code to Use the Web API
Creating the Basic Functionality
Adding Support for Editing New Reservations
Adding Support for Deleting Reservations
Adding Support for Creating Reservations
Summary
Chapter 26: Deployment
Preparing an Application for Deployment
Detecting View Errors
Disabling Debug Mode
Removing Unused Connection Strings
Preparing Windows Azure
Creating the Web Site and Database
Preparing the Database for Remote Administration
Creating the Schema
Deploying the Application
Summary
Index
← Prev
Back
Next →
← Prev
Back
Next →