Home > Store

ASP.NET MVC Framework Unleashed

Register your product to gain access to bonus material or receive a coupon.

ASP.NET MVC Framework Unleashed

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2010
  • Dimensions: 7" x 9-1/8"
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-32998-0
  • ISBN-13: 978-0-672-32998-2

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

Sample Content

Online Sample Chapter

An Introduction to ASP.NET MVC

Sample Pages

Download the sample pages (includes Chapter 1 and Index)

Table of Contents

Introduction 1

How This Book Is Organized      1

What You Should Know Before Reading This Book     2

What Software Do You Need?      2

Where Do You Download the Code Samples?     3

If You Like This Book          3

Part I Building ASP.NET MVC Applications

Chapter 1 An Introduction to ASP.NET MVC     7

A Story with a Moral         7

What Is Good Software?      8

Avoiding Code Smells    9

Software Design Principles      10

Software Design Patterns      11

Writing Unit Tests for Your Code     12

Test-Driven Development     13

Short-Term Pain, Long-Term Gain      14

What Is ASP.NET MVC?      14

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

The Origins of MVC      15

The Architecture of an ASP.NET MVC Application     16

Understanding the Sample ASP.NET MVC Application     17

ASP.NET MVC Folder Conventions     19

Running the Sample ASP.NET MVC Application     19

Chapter 2 Building a Simple ASP.NET MVC Application 23

Starting with a Blank Slate     23

Creating the Database          25

Creating the Model          27

Creating the Controller      30

Creating the Views          37

Adding the Index View     38

Adding the Create View      42

Chapter 3 Understanding Controllers and Actions     47

Creating a Controller          47

Returning Action Results      51

Returning a View Result      52

Returning a Redirect Result      55

Returning a Content Result     57

Returning a JSON Result     59

Returning a File Result     63

Controlling How Actions Are Invoked     65

Using AcceptVerbs      65

Using ActionName     70

Using ActionMethodSelector     72

Handling Unknown Actions     76

Testing Controllers and Actions      78

Chapter 4 Understanding Views 83

Creating a View          83

Using View Data           87

Typed and Untyped Views     88

Creating Strongly Typed Views      94

Preventing JavaScript Injection Attacks      95

Using Alternative View Engines      97

Creating a Custom View Engine      99

Testing Views          105

Test the View Result     105

Test HTML Helpers      108

Test a Custom View Engine     114

Chapter 5 Understanding Models     119

Creating a Data Model     120

Creating a Data Model with the Microsoft Entity Framework     120

Listing Records          124

Getting a Single Record      126

Creating Records     127

Editing Records           128

Deleting Records     131

Using the Repository Pattern     132

Creating a Product Repository      133

Using the Dependency Injection Pattern      138

Creating a Generic Repository     139

Using the Generic Repository with the Entity Framework     141

Using the Generic Repository with LINQ to SQL     144

Extending the Generic Repository      147

Testing Data Access           149

Testing with a Mock Repository     150

Testing with a Fake Generic Repository     155

Chapter 6 Understanding HTML Helpers 159

Using the Standard HTML Helpers     160

Rendering Links     160

Rendering Image Links     161

Rendering Form Elements      162

Rendering a Form      166

Rendering a Drop-Down List     167

Encoding HTML Content     169

Using Antiforgery Tokens     169

Creating Custom HTML Helpers      173

Using the TagBuilder Class      176

Using the HtmlTextWriter Class     180

Creating a DataGrid Helper      183

Adding Sorting to the DataGrid Helper      190

Adding Paging to the DataGrid Helper     192

Testing Helpers     201

Chapter 7 Understanding Model Binders and Action Filters     207

Understanding Model Binders     207

Using the Default Model Binder      210

Binding to Complex Classes     212

Using the Bind Attribute      218

Using Bind with Classes      221

Using Prefixes When Binding      225

Using the Form Collection Model Binder     228

Using the HTTP Posted File Base Model Binder     231

Creating a Custom Model Binder      233

Understanding Action Filters     236

Creating a Log Action Filter      237

Chapter 8 Validating Form Data 241

Understanding Model State      241

Understanding the Validation Helpers     245

Styling Validation Error Messages      247

Prebinding and Postbinding Validation      248

Validating with a Service Layer      251

Validating with the IDataErrorInfo Interface     258

Testing Validation           264

Chapter 9 Understanding Routing     269

Using the Default Route      269

Debugging Routes           274

Creating Custom Routes     275

Creating Route Constraints      277

Using Regular Expression Constraints      278

Using the HttpMethod Constraint     280

Creating an Authenticated Constraint     280

Creating a NotEqual Constraint     283

Using Catch-All Routes      285

Testing Routes           288

Using the MvcFakes and RouteDebugger Assemblies     289

Testing If a URL Matches a Route      289

Testing Routes with Constraints      292

Chapter 10 Understanding View Master Pages and View User Controls     295

Understanding View Master Pages      295

Creating a View Master Page      295

Creating a View Content Page      300

Setting the Master Page from the Controller     302

Setting the Master Page Title      303

Nested Master Pages      306

Passing View Data to Master Pages      308

Understanding View User Controls     311

Passing View Data to User Controls     314

Using a View User Control as a Template     319

Chapter 11 Better Performance with Caching     325

Using the OutputCache Attribute      325

Don’t Cache Private Data      330

What Gets Cached?      331

Setting the Cache Location      333

Varying the Output Cache by Parameter     335

Varying the Output Cache      337

Removing Items from the Output Cache      341

Using Cache Profiles     343

Using the Cache API           344

Using the HttpCachePolicy Class     345

Using the Cache Class      347

Testing the Cache          353

Testing the OutputCache Attribute    353

Testing Adding Data to the Cache     355

Chapter 12 Authenticating Users     365

Creating Users and Roles      365

Using the Web Site Administration Tool      365

Using the Account Controller      367

Authorizing Users           368

Using the Authorize Attribute     368

Using the User Property      372

Configuring Membership      374

Configuring the Membership Database      375

Configuring Membership Settings      378

Using the Membership and Role Manager API      381

Using Windows Authentication      385

Configuring Windows Authentication      385

Authenticating Windows Users and Groups     386

Testing Authorization      390

Testing for the Authorize Attribute      390

Testing with the User Model Binder      393

Chapter 13 Deploying ASP.NET MVC Applications     401

Configuring IIS for ASP.NET MVC     401

Integrated Versus Classic Mode     402

Using ASP.NET MVC with Older Versions of IIS     403

Adding Extensions to the Route Table     403

Hosted Server           408

Creating a Wildcard Script Map      410

Mixing ASP.NET Web Forms and ASP.NET MVC     414

Modifying the Visual Studio Project File      415

Adding the Required Assemblies     415

Modifying the Web Configuration File     416

Modify the Global.asax File     422

Using Web Forms and MVC     424

Bin Deploying an ASP.NET MVC Application     424

Chapter 14 Working with Ajax     427

Using the Ajax Helpers      427

Debugging Ajax          428

Posting a Form Asynchronously     430

Displaying Progress     435

Updating Content After Posting      443

Performing Validation      447

Providing Downlevel Browser Support      452

Retrieving Content Asynchronously      454

Highlighting the Selected Link     459

Creating a Delete Link     462

Providing Downlevel Browser Support      468

Using the AcceptAjax Attribute      473

Chapter 15 Using jQuery     479

Overview of jQuery       479

Including the jQuery Library     480

jQuery and Visual Studio Intellisense      481

Using jQuery Selectors      482

Adding Event Handlers     487

Using jQuery Animations      489

jQuery and Ajax          491

Using jQuery Plug-Ins     498

Part II Walkthrough: Building the Unleashed Blog Application

Chapter 16 Overview of the Application     505

What Is Test-Driven Development?      505

Why Do Test-Driven Development?      506

The KISS and YAGNI Principles      507

Waterfall Versus Evolutionary Design      507

TDD Tests Are Not Unit Tests      508

Tests Flow from User Stories      508

Unit Testing Frameworks      509

Bibliography of Test-Driven Development     509

Chapter 17 Database Access     511

Creating the Unleashed Blog Project     511

Creating Our First Test     514

Creating New Blog Entries     520

Refactoring to Use the Repository Pattern       524

Creating a Fake Blog Repository     526

Creating an Entity Framework Repository      530

Creating the Database Objects      531

Creating the Entity Framework Data Model     532

Creating the Entity Framework Blog Repository     534

Using the Entity Framework Repository      537

Chapter 18 Creating the Routes     543

Creating the Controller Tests     543

Creating the Route Tests      553

Creating the Archive Routes     561

Trying Out the Archive Controller      564

Chapter 19 Adding Validation 567

Performing Validation in the Simplest Possible Way     567

Refactoring the Test Code     573

Validating the Length of a Property     576

A Web Browser Sanity Check     578

Refactoring to Use a Service Layer     581

Adding Business Rules      586

Chapter 20 Paging, Views, and Ajax     593

Adding Paging Support     593

Adding the Views      605

Adding Ajax Support      612

Chapter 21 Adding Comments     621

Implementing Comments      621

Adding Comments to the Database      633

Displaying Comments and Comment Counts      637

Part III Appendixes

Appendix A C# and VB.NET Language Features     647

Type Inference       647

Object Initializers       648

Anonymous Types     649

Nullable Types          651

Extension Methods           652

Generics          654

Lambda Expressions          655

LINQ          656

Appendix B Using a Unit Testing Framework     659

Using Visual Studio Unit Test     660

Understanding the Test Attributes      666

Using Assertions      669

Running the Tests      669

Limiting Visual Studio Test Results      671

Using NUnit           672

Creating an NUnit Unit Test Project     672

Creating a Test         674

Running Tests           676

Appendix C Using a Mock Object Framework 679

Understanding the Terminology      680

Installing Moq          680

Using Moq to Create a Class from an Interface     681

Returning Fake Values     690

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020