In this book, world-renowned ASP.NET expert and member of the Microsoft ASP.NET team Stephen Walther shows experienced developers how to use Microsoft’s new ASP.NET MVC Framework to build web applications that are more powerful, flexible, testable, manageable, scalable, and extensible. Writing for professional programmers, Walther explains the crucial concepts that make the Model-View-Controller (MVC) development paradigm work so well and shows exactly how to apply them with the ASP.NET MVC Framework. From controllers and actions to views and models, Walther demonstrates how to apply each ASP.NET MVC Framework feature in real-world projects. In Part II, you’ll walk step-by-step through building a full-fledged ASP.NET MVC blog application that implements capabilities ranging from data access to validation. Through this case study, you’ll learn how to build ASP.NET MVC applications using test-driven development processes that enable rapid feedback, greater productivity, and better quality. Throughout, Walther presents extensive code examples, reflecting his unsurpassed experience as an ASP.NET instructor, a leading commercial developer, and now as a member of Microsoft’s ASP.NET development team. Understand how to: Build enterprise-scale web applications far more rapidly and effectively Develop web applications that are easier to maintain and extend over time Gain unprecedented control over the appearance of your website or application Expose intuitive URLs that are friendlier to search engines and users alike Create ASP.NET MVC models that contain all your application’s business, validation, and data access logic Make the most of HTML helpers, model binders, action filters, routing, and authentication Efficiently deploy your ASP.NET MVC applications Use the lightweight JQuery JavaScript library to easily find and manipulate HTML elements Create ASP.NET MVC applications using unit test and mock object framework
Author(s): Stephen Walther
Edition: 1
Publisher: Sams Publishing
Year: 2009
Language: English
Pages: 744
Wow! eBook......Page 0
Table of Contents......Page 5
How This Book Is Organized......Page 16
What Software Do You Need?......Page 17
If You Like This Book......Page 18
Part I: Building ASP.NET MVC Applications......Page 20
A Story with a Moral......Page 22
What Is Good Software?......Page 23
What Is ASP.NET MVC?......Page 29
The Architecture of an ASP.NET MVC Application......Page 31
Understanding the Sample ASP.NET MVC Application......Page 32
Starting with a Blank Slate......Page 38
Creating the Database......Page 40
Creating the Model......Page 42
Creating the Controller......Page 45
Creating the Views......Page 52
Creating a Controller......Page 62
Returning Action Results......Page 66
Controlling How Actions Are Invoked......Page 80
Handling Unknown Actions......Page 91
Testing Controllers and Actions......Page 93
Creating a View......Page 98
Using View Data......Page 102
Typed and Untyped Views......Page 103
Preventing JavaScript Injection Attacks......Page 110
Using Alternative View Engines......Page 112
Testing Views......Page 120
5 Understanding Models......Page 134
Creating a Data Model......Page 135
Using the Repository Pattern......Page 147
Creating a Generic Repository......Page 154
Testing Data Access......Page 164
6 Understanding HTML Helpers......Page 174
Using the Standard HTML Helpers......Page 175
Creating Custom HTML Helpers......Page 188
Creating a DataGrid Helper......Page 198
Testing Helpers......Page 216
Understanding Model Binders......Page 222
Understanding Action Filters......Page 251
Understanding Model State......Page 256
Understanding the Validation Helpers......Page 260
Styling Validation Error Messages......Page 262
Prebinding and Postbinding Validation......Page 263
Validating with a Service Layer......Page 266
Validating with the IDataErrorInfo Interface......Page 273
Testing Validation......Page 279
Using the Default Route......Page 284
Debugging Routes......Page 289
Creating Custom Routes......Page 290
Creating Route Constraints......Page 292
Using Catch-All Routes......Page 300
Testing Routes......Page 303
Understanding View Master Pages......Page 310
Understanding View User Controls......Page 326
Using the OutputCache Attribute......Page 340
Using the Cache API......Page 359
Testing the Cache......Page 368
Creating Users and Roles......Page 380
Authorizing Users......Page 383
Configuring Membership......Page 389
Using the Membership and Role Manager API......Page 396
Using Windows Authentication......Page 400
Testing Authorization......Page 405
Configuring IIS for ASP.NET MVC......Page 416
Mixing ASP.NET Web Forms and ASP.NET MVC......Page 429
Bin Deploying an ASP.NET MVC Application......Page 439
Using the Ajax Helpers......Page 442
Debugging Ajax......Page 443
Posting a Form Asynchronously......Page 445
Retrieving Content Asynchronously......Page 469
Using the AcceptAjax Attribute......Page 488
Overview of jQuery......Page 494
Including the jQuery Library......Page 495
jQuery and Visual Studio Intellisense......Page 496
Using jQuery Selectors......Page 497
Adding Event Handlers......Page 502
Using jQuery Animations......Page 504
jQuery and Ajax......Page 506
Using jQuery Plug-Ins......Page 513
Part II: Walkthrough: Building the Unleashed Blog Application......Page 518
What Is Test-Driven Development?......Page 520
Why Do Test-Driven Development?......Page 521
Waterfall Versus Evolutionary Design......Page 522
Tests Flow from User Stories......Page 523
Bibliography of Test-Driven Development......Page 524
Creating the Unleashed Blog Project......Page 526
Creating Our First Test......Page 529
Creating New Blog Entries......Page 535
Refactoring to Use the Repository Pattern......Page 539
Creating a Fake Blog Repository......Page 541
Creating an Entity Framework Repository......Page 545
Creating the Controller Tests......Page 558
Creating the Route Tests......Page 568
Creating the Archive Routes......Page 576
Trying Out the Archive Controller......Page 579
Performing Validation in the Simplest Possible Way......Page 582
Refactoring the Test Code......Page 588
Validating the Length of a Property......Page 591
A Web Browser Sanity Check......Page 593
Refactoring to Use a Service Layer......Page 596
Adding Business Rules......Page 601
Adding Paging Support......Page 608
Adding the Views......Page 620
Adding Ajax Support......Page 627
Implementing Comments......Page 636
Adding Comments to the Database......Page 648
Displaying Comments and Comment Counts......Page 652
Part III: Appendixes......Page 660
Type Inference......Page 662
Object Initializers......Page 663
Anonymous Types......Page 664
Nullable Types......Page 666
Extension Methods......Page 667
Generics......Page 669
Lambda Expressions......Page 670
LINQ......Page 671
B: Using a Unit Testing Framework......Page 674
Using Visual Studio Unit Test......Page 675
Using NUnit......Page 687
C: Using a Mock Object Framework......Page 694
Installing Moq......Page 695
Using Moq to Create a Class from an Interface......Page 696
Returning Fake Values......Page 705
A......Page 710
B......Page 713
C......Page 714
D......Page 720
E......Page 721
G......Page 722
H......Page 723
I......Page 724
J-K......Page 725
M......Page 726
O......Page 728
P......Page 729
Q-R......Page 730
S......Page 732
T......Page 733
U......Page 734
V......Page 736
X-Y-Z......Page 738