Commit 4e8e2f48 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit


Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
Programming Microsoft ASP.NET MVC == Table of Contents
Chapter 1: Goals of ASP.NET MVC and Motivation for Its Development
The Deep Impact of ASP.NET
Productivity Is King
The Web Forms Model
The “Page Controller” Pattern
The ASP.NET Age of Reason
ASP.NET’s Signs of Aging
The Turning Point
ASP.NET MVC at a Glance
ASP.NET MVC Highlights
Web Forms vs. ASP.NET MVC
Chapter 2: The Runtime Environment
The ASP.NET Runtime Machinery
ASP.NET and the IIS Web Server
Life Cycle of an ASP.NET Request
What’s an HTTP Handler, Anyway?
What’s an HTTP Module, Anyway?
URL Routing
The ASP.NET MVC Run-Time Shell
The Big Picture
Processing an ASP.NET MVC Request
Chapter 3: The MVC Pattern and Beyond
The Original MVC Pattern
MVC Interaction Model
The Original Idea
Presenting the Actors
Limitations of the MVC Pattern
The Model2 Pattern
MVC and the Web
Model2 and ASP.NET MVC
Presentation-Oriented Variations of MVC
The MVP Pattern
Presentation Model Pattern (Also Known as MVVM)
The ASP.NET MVC Project Template
Peculiarities of an ASP.NET MVC Project
ASP.NET MVC Special Folders
Chapter 4: Inside Controllers
The Role of Controllers and the Motivation for Using Them
Beyond the Code-Behind Approach
Introducing Controllers
Mechanics of Controllers in ASP.NET MVC
Anatomy of an ASP.NET MVC Controller
Inside the Structure of a Controller
Behavior of a Controller
Attributes of Controllers and Action Methods
Writing a Controller
Design of a Controller Class
Should You Use Your Own Base Class?
Special Capabilities
Grouping Controllers
Asynchronous Controllers
Render Actions
Controllers and Testability
Making Controllers Easy to Test
Writing Unit Tests
Chapter 5: Inside Views
Views and Controllers
From Controllers to Views
Building the Response for the Browser
Anatomy of an ASP.NET MVC View
Selecting the View
Creating the View
The Default View Engine
The Web Forms View Engine
Writing a View
The View’s Template
Filling Up the View
HTML Helpers
Templated HTML Helpers
Datagrids and Paged Views
Testing a View
Chapter 6: Inside Models
What’s the Model, Anyway?
How Many Types of Models Do You Know?
The Models Folder
Domain Model and View-Model
Business Object Modeling
Adding Validation Logic to the Model
Data for the View
Model Binding
The Model Binder in Action
Chapter 7: Data Entry in ASP.NET MVC
The Select-Edit-Save Pattern
Presenting Data
Editing Data
Saving Data
Data Validation
Validation on the Server Side
Giving Feedback to the User
Data Annotations and Validators
Client-Side Validation
Chapter 8: The ASP.NET MVC Infrastructure
Dealing with Routes
Keeping an Eye on SEO
Error Handling
Foundations of ASP.NET Error Handling
Dealing with Missing Content
Making Resources Localizable
Dealing with Resources in ASP.NET MVC
Dependency Injection
Dependency Inversion in Action
A Brief Tour of Unity
Creating a Global Container
Chapter 9: AJAX Capabilities
Partial Rendering
Direct Scripting
The JavaScript API
The Controller Façade
Partial Rendering in ASP.NET MVC
Chapter 10: Testability and Unit Testing
Testability and Design
Design for Testability
Loosen Up Your Design
Basics of Unit Testing
Working with a Test Harness
Aspects of Testing
Unit Testing in ASP.NET MVC
Testing Controller Actions
Injecting Mocks and Fakes
Mocking the HTTP Context
More Specific Tests
Chapter 11: Customizing ASP.NET MVC
The Controller Factory
ASP.NET MVC Request Processing
Extending the Default Controller Factory
Invoking Actions
Action Filters
Gallery of Action Filters
Loading Action Filters Dynamically
Action Selectors
Action Results and Rendering
Processing the Result of the Action
Custom ActionResult Objects
View Engines
HTML Helpers
Appendix: ReSharper and the Power of Tools
Sample Customization Readme
Programming Microsoft ASP.NET MVC
by Dino Esposito
Copyright (c) 2010 by Microsoft Corporation
Portions copyright (c) 2010 by Dino Esposito
All Rights Reserved
1) The sample application may be compiled with either Visual Studio 2010 (MvcGallery.sln) or Visual Studio 2008 (MvcGallery2008.sln). In both cases, Visual Studio must be combined with ASP.NET MVC 2. You may download a trial version of Visual Studio 2010 from the following URL:
ASP.NET MVC 2 may be downloaded from this URL:
2) The sample uses information contained within the Northwind database. If you do not have the Northwind database, you can download it from the following URL:
(Ignore the mention of SQL Server can install and use this database with later versions of SQL Server as well.) Once downloaded and installed, the necessary SQL command file will be placed in the installation folder you specified during installation (defaulting to "C:\SQL Server 2000 Sample Databases"). There will also be a "readme" HTML file that should help answer any questions you may have.
3) You must provide your server information in the connection string used by the business logic component, which you will find located within the MvcGallery.Business project found under Lib. To edit the connection string, load the MvcGallery solution into Visual Studio 2010 and open the settings (Settings.settings, found under Properties). There you will find the connection string available for editing. Currently, the connection string assumes the following server:
It also assumes Windows Authentication. Most readers should find this connection string sufficient. However, modify it as required to work with your local server. Failing to do so will result in data errors when running the sample application.
4) You will need to download and install both the Unity Application Block and Rhino Mocks to run this sample application:
Rhino Mocks:
Note you may also have to re-reference these assemblies. The Unity references are located in MvcGallery.Unity project, while thr Rhino Mocks references are in two test projects: HttpContextTests and SimpleCoordinatorTests.
5) To run the samples, first compile the entire solution. Then, select one of the many projects under Src in Solution Explorer and click the Debug button or press F5. The page for the sample will appear. You will find three tabs: the sample tab, the author tab, and an explanation tab. The sample tab will contain links and descriptive text designed to experiment with the given ASP.NET MVC task at hand. The author tab provides information about the book and training provided by the author. And the explanation tab provides additional insight regarding the particular aspects of ASP.NET MVC being demonstrated. Feel free to experiment!
Namespace MvcGallery.Business
Partial Public Class Customer
Public ReadOnly Property FullAddress() As String
Return String.Format("{0}, {1} {2}", Address, PostalCode, City)
End Get
End Property
End Class
End Namespace
Namespace MvcGallery.Business
Public Class MissingProduct
Inherits Product
End Class
End Namespace
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="">
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<UpgradeBackupLocation />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Reference Include="System" />
<Reference Include="System.Core">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq">
<Import Include="Microsoft.VisualBasic" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Diagnostics" />
<Import Include="System.Data" />
<Import Include="System.Linq" />
<Import Include="System" />
<Compile Include="Extensions\Customer.vb" />
<Compile Include="Extensions\MissingProduct.vb" />
<Compile Include="Northwind.designer.vb">
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Settings.Designer.vb">
<None Include="Northwind.dbml">
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
<None Include="app.config" />
<None Include="Northwind.dbml.layout">
<None Include="My Project\Settings.settings">
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<ProductName>.NET Framework 3.5 SP1</ProductName>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<ProductName>Windows Installer 3.1</ProductName>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
<Target Name="AfterBuild">
\ No newline at end of file
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
<Assembly: AssemblyTitle("MvcGallery.Business")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyConfiguration("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("MvcGallery.Business")>
<Assembly: AssemblyCopyright("Copyright © 2010")>
<Assembly: AssemblyTrademark("")>
<Assembly: AssemblyCulture("")>
' Setting ComVisible to false makes the types in this assembly not visible
' to COM components. If you need to access a type in this assembly from
' COM, set the ComVisible attribute to true on that type.
<Assembly: ComVisible(False)>
' The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("d51037c9-e315-4d39-a92f-ced0ee58ff62")>
' Version information for an assembly consists of the following four values:
' Major Version
' Minor Version
' Build Number
' Revision
' You can specify all the values or you can default the Build and Revision Numbers
' by Using the '*' as shown below:
' [assembly: AssemblyVersion("1.0.*")]
<Assembly: AssemblyVersion("")>
<Assembly: AssemblyFileVersion("")>
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.1
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "")> _
Friend NotInheritable Partial Class Settings
Inherits System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As Settings = (CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()), Settings))
Public Shared ReadOnly Property [Default]() As Settings
Return defaultInstance
End Get
End Property
<Global.System.Configuration.ApplicationScopedSettingAttribute(), Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.ConnectionString), Global.System.Configuration.DefaultSettingValueAttribute("Data Source=.\;Initial Catalog=Northwind;uid=sa;pwd=sa")> _
Public ReadOnly Property NorthwindConnectionString() As String
Return (CStr(Me("NorthwindConnectionString")))
End Get
End Property
End Class
End Namespace
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="" CurrentProfile="(Default)" GeneratedClassNamespace="MvcGallery.Business.Properties" GeneratedClassName="Settings">
<Profiles />
<Setting Name="NorthwindConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="" xmlns:xsd=""&gt;
&lt;ConnectionString&gt;Data Source=.\;Initial Catalog=Northwind;uid=sa;pwd=sa&lt;/ConnectionString&gt;
<Value Profile="(Default)">Data Source=.\;Initial Catalog=Northwind;uid=sa;pwd=sa</Value>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Database Name="Northwind" Class="NorthwindDataContext" xmlns="">
<Connection Mode="AppSettings" ConnectionString="Data Source=MY-LAPTOP;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa" SettingsObjectName="MvcGallery.Business.Properties.Settings" SettingsPropertyName="NorthwindConnectionString" Provider="System.Data.SqlClient" />
<Table Name="dbo.Customers" Member="Customers">
<Type Name="Customer">
<Column Name="CustomerID" Type="System.String" DbType="NChar(5) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="CompanyName" Type="System.String" DbType="NVarChar(40) NOT NULL" CanBeNull="false" />
<Column Name="ContactName" Type="System.String" DbType="NVarChar(30)" CanBeNull="true" />
<Column Name="ContactTitle" Type="System.String" DbType="NVarChar(30)" CanBeNull="true" />
<Column Name="Address" Type="System.String" DbType="NVarChar(60)" CanBeNull="true" />
<Column Name="City" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="Region" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="PostalCode" Type="System.String" DbType="NVarChar(10)" CanBeNull="true" />
<Column Name="Country" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="Phone" Type="System.String" DbType="NVarChar(24)" CanBeNull="true" />
<Column Name="Fax" Type="System.String" DbType="NVarChar(24)" CanBeNull="true" />
<Association Name="Customer_Order" Member="Orders" ThisKey="CustomerID" OtherKey="CustomerID" Type="Order" />
<Table Name="dbo.Employees" Member="Employees">
<Type Name="Employee">
<Column Name="EmployeeID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
<Column Name="LastName" Type="System.String" DbType="NVarChar(20) NOT NULL" CanBeNull="false" />
<Column Name="FirstName" Type="System.String" DbType="NVarChar(10) NOT NULL" CanBeNull="false" />
<Column Name="Title" Type="System.String" DbType="NVarChar(30)" CanBeNull="true" />
<Column Name="TitleOfCourtesy" Type="System.String" DbType="NVarChar(25)" CanBeNull="true" />
<Column Name="BirthDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="HireDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="Address" Type="System.String" DbType="NVarChar(60)" CanBeNull="true" />
<Column Name="City" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="Region" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="PostalCode" Type="System.String" DbType="NVarChar(10)" CanBeNull="true" />
<Column Name="Country" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="HomePhone" Type="System.String" DbType="NVarChar(24)" CanBeNull="true" />
<Column Name="Extension" Type="System.String" DbType="NVarChar(4)" CanBeNull="true" />
<Column Name="Photo" Type="System.Data.Linq.Binary" DbType="Image" CanBeNull="true" UpdateCheck="Never" />
<Column Name="Notes" Type="System.String" DbType="NText" CanBeNull="true" UpdateCheck="Never" />
<Column Name="ReportsTo" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="PhotoPath" Type="System.String" DbType="NVarChar(255)" CanBeNull="true" />
<Association Name="Employee_Employee" Member="Employees" ThisKey="EmployeeID" OtherKey="ReportsTo" Type="Employee" />
<Association Name="Employee_Order" Member="Orders" ThisKey="EmployeeID" OtherKey="EmployeeID" Type="Order" />
<Association Name="Employee_Employee" Member="Employee1" ThisKey="ReportsTo" OtherKey="EmployeeID" Type="Employee" IsForeignKey="true" />
<Table Name="dbo.Orders" Member="Orders">
<Type Name="Order">
<Column Name="OrderID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
<Column Name="CustomerID" Type="System.String" DbType="NChar(5)" CanBeNull="true" />
<Column Name="EmployeeID" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="OrderDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="RequiredDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="ShippedDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="ShipVia" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="Freight" Type="System.Decimal" DbType="Money" CanBeNull="true" />
<Column Name="ShipName" Type="System.String" DbType="NVarChar(40)" CanBeNull="true" />
<Column Name="ShipAddress" Type="System.String" DbType="NVarChar(60)" CanBeNull="true" />
<Column Name="ShipCity" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="ShipRegion" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Column Name="ShipPostalCode" Type="System.String" DbType="NVarChar(10)" CanBeNull="true" />
<Column Name="ShipCountry" Type="System.String" DbType="NVarChar(15)" CanBeNull="true" />
<Association Name="Order_Order_Detail" Member="Order_Details" ThisKey="OrderID" OtherKey="OrderID" Type="Order_Detail" />
<Association Name="Customer_Order" Member="Customer" ThisKey="CustomerID" OtherKey="CustomerID" Type="Customer" IsForeignKey="true" />
<Association Name="Employee_Order" Member="Employee" ThisKey="EmployeeID" OtherKey="EmployeeID" Type="Employee" IsForeignKey="true" />
<Table Name="dbo.[Order Details]" Member="Order_Details">
<Type Name="Order_Detail">
<Column Name="OrderID" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="ProductID" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="UnitPrice" Type="System.Decimal" DbType="Money NOT NULL" CanBeNull="false" />
<Column Name="Quantity" Type="System.Int16" DbType="SmallInt NOT NULL" CanBeNull="false" />
<Column Name="Discount" Type="System.Single" DbType="Real NOT NULL" CanBeNull="false" />
<Association Name="Order_Order_Detail" Member="Order" ThisKey="OrderID" OtherKey="OrderID" Type="Order" IsForeignKey="true" />
<Association Name="Product_Order_Detail" Member="Product" ThisKey="ProductID" OtherKey="ProductID" Type="Product" IsForeignKey="true" />
<Table Name="dbo.Products" Member="Products">
<Type Name="Product">
<Column Name="ProductID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
<Column Name="ProductName" Type="System.String" DbType="NVarChar(40) NOT NULL" CanBeNull="false" />
<Column Name="SupplierID" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="CategoryID" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="QuantityPerUnit" Type="System.String" DbType="NVarChar(20)" CanBeNull="true" />
<Column Name="UnitPrice" Type="System.Decimal" DbType="Money" CanBeNull="true" />
<Column Name="UnitsInStock" Type="System.Int16" DbType="SmallInt" CanBeNull="true" />
<Column Name="UnitsOnOrder" Type="System.Int16" DbType="SmallInt" CanBeNull="true" />
<Column Name="ReorderLevel" Type="System.Int16" DbType="SmallInt" CanBeNull="true" />
<Column Name="Discontinued" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
<Association Name="Product_Order_Detail" Member="Order_Details" ThisKey="ProductID" OtherKey="ProductID" Type="Order_Detail" />
<Function Name="dbo.CustOrderHist" Method="CustOrderHist">
<Parameter Name="CustomerID" Parameter="customerID" Type="System.String" DbType="NChar(5)" />
<ElementType Name="CustOrderHistResult">
<Column Name="ProductName" Type="System.String" DbType="NVarChar(40) NOT NULL" CanBeNull="false" />
<Column Name="Total" Type="System.Int32" DbType="Int" CanBeNull="true" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ordesignerObjectsDiagram dslVersion="" absoluteBounds="0, 0, 13.5, 8.5" name="Northwind">
<DataContextMoniker Name="/NorthwindDataContext" />
<classShape Id="53743a20-5d7f-4db0-914b-9d7ecb1519ad" absoluteBounds="0.5, 1.125, 2, 2.9247054036458331">