ASP.NET MVC insiders cover the latest updates to the technology in this popular Wrox reference
MVC 5 is the newest update to the popular Microsoft technology that enables you to build dynamic, data-driven websites. Like previous versions, this guide shows you step-by-step techniques on using MVC to best advantage, with plenty of practical tutorials to illustrate the concepts. It covers controllers, views, and models; forms and HTML helpers; data annotation and validation; membership, authorization, and security.
MVC 5, the latest version of MVC, adds sophisticated features such as single page applications, mobile optimization, and adaptive renderingA team of top Microsoft MVP experts, along with visionaries in the field, provide practical advice on basic and advanced MVC topicsCovers controllers, views, models, forms, data annotations, authorization and security, Ajax, routing, ASP.NET web API, dependency injection, unit testing, real-world application, and much more
Professional ASP.NET MVC 5 is the comprehensive resource you need to make the best use of the updated Model-View-Controller technology.
Foreword xxvii
Introduction xxix
Chapter 1: Getting Started 1
A Quick Introduction to ASP.NET MVC 1
ASP.NET MVC 5 Overview 11
Installing MVC 5 and Creating Applications 16
The MVC Application Structure 24
Summary 29
Chapter 2: Controllers 31
The Controllers Role 31
A Sample Application: The MVC Music Store 34
Controller Basics 38
Summary 47
Chapter 3: Views 49
The Purpose of Views 50
View Basics 50
Understanding View Conventions 54
Strongly Typed Views 55
View Models 58
Adding a View 60
The Razor View Engine 63
Specifying a Partial View 73
Summary 74
Chapter 4: Models 75
Modeling the Music Store 76
Scaffolding a Store Manager 80
Editing an Album 97
Model Binding 103
Summary 107
Chapter 5: Forms and Html Helpers 109
Using Forms 110
HTML Helpers 114
Other Input Helpers 129
Rendering Helpers 130
Summary 135
Chapter 6: Data Annotations and Validation 137
Annotating Orders for Validation 138
Custom Validation Logic 150
Display and Edit Annotations 155
Summary 158
Chapter 7: Membership, Authorization, and Security 159
Security: Not fun, But Incredibly Important 159
Using the Authorize Attribute to Require Login 162
Using AuthorizeAttribute to Require Role Membership 172
Extending User Identity 174
External Login via OAuth and OpenID 175
Understanding the Security Vectors in a Web Application 182
Proper Error Reporting and the Stack Trace 207
Security Recap and Helpful Resources 209
Summary 211
Chapter 8: Ajax 213
jQuery 214
Ajax Helpers 225
Client Validation 233
Beyond Helpers 241
Improving Ajax Performance 253
Summary 255
Chapter 9: Routing 257
Uniform Resource Locators 258
Introduction to Routing 259
Inside Routing: How Routes Generate URLs 288
Inside Routing: How Routes Tie Your URL to an Action 294
Chapter 10: Nuget 299
Introduction to NuGet 299
Adding a Library as a Package 301
Creating Packages 312
Publishing Packages 325
Summary 332
Chapter 11: Asp.Net Web Api 333
Defining ASP.NET Web API 334
Getting Started with Web API 335
Writing an API Controller 335
Configuring Web API 342
Adding Routes to Your Web API 346
Binding Parameters 347
Filtering Requests 349
Enabling Dependency Injection 350
Exploring APIs Programmatically 350
Tracing the Application 352
Web API Example: ProductsController 352
Summary 354
Chapter 12: Single Page Applications With Angularjs 355
Understanding and Setting Up AngularJS 356
Building the Web API 363
Building Applications and Modules 364
Summary 384
Chapter 13: Dependency Injection 385
Software Design Patterns 385
Dependency Resolution in MVC 395
Dependency Resolution in Web API 402
Summary 405
Chapter 14: Unit Testing 407
Understanding Unit Testing and Test-Driven Development 408
Building a Unit Test Project 412
Advice for Unit Testing Your ASP.NET MVC and ASP.NET Web API Applications 415
Summary 427
Chapter 15: Extending Mvc 429
Extending Models 430
Extending Views 442
Extending Controllers 446
Summary 458
Chapter 16: Advanced Topics 461
Mobile Support 461
Advanced Razor 473
Advanced View Engines 476
Advanced Scaffolding 482
Advanced Routing 486
Advanced Templates 492
Advanced Controllers 498
Summary 520
Chapter 17: Real-World Asp.Net Mvc: Building The Nuget.Org Website 521
May the Source Be with You 522
WebActivator 526
ASP.NET Dynamic Data 527
Exception Logging 530
Profiling 532
Data Access 535
EF CodeBased Migrations 536
Deployments with Octopus Deploy 539
Automated Browser Testing with Fluent Automation 540
Other Useful NuGet Packages 541
Summary 544
Appendix: ASP.NET MVC 5.1 545
ASP.NET MVC 5.1 Release Description 545
Enum Support in ASP.NET MVC Views 549
Attribute Routing with Custom Constraints 553
Bootstrap and JavaScript Enhancements 558
Summary 563
Index 565