Introduction

It's a great time to be an ASP.NET developer!

Whether you've been developing with ASP.NET for years or are just getting started, now is a great time to dig into ASP.NET MVC. ASP.NET MVC has been a lot of fun to work with from the start, but the last two releases have added many features that make the entire development process really enjoyable.

ASP.NET MVC 3 brought features like the Razor view engine, integration with the NuGet package management system, and built-in integration with jQuery to simplify Ajax development. ASP.NET MVC 5 continues that trend, with a refreshed visual design, mobile web support, easier HTTP services using ASP.NET Web API, easier integration with popular sites with built-in OAuth support, and more. The combined effect is that you can get started quickly with full-featured web applications.

This isn't just drag-and-drop short-term productivity, either. It's all built on a solid, patterns-based web framework that gives you total control over every aspect of your application, when you want it.

Join us for a fun, informative tour of ASP.NET MVC 5!

Who This Book Is For

Professional ASP.NET MVC 5 is designed to teach ASP.NET MVC, from a beginner level through advanced topics.

If you are new to ASP.NET MVC, this book gets you started by explaining the concepts, and then helps you apply them through plenty of hands-on code examples. The authors have taught thousands of developers how to get started with ASP.NET MVC and know how to cut through boring rhetoric to get you up and running quickly.

We understand that many of our readers are familiar with ASP.NET Web Forms, so in some places we'll point out some similarities and differences to help put things in context. It's worth noting that ASP.NET MVC 5 is not a replacement for ASP.NET Web Forms. Many web developers have been giving a lot of attention to other web frameworks (Ruby on Rails, Node.js, Django, several PHP frameworks, etc.) that have embraced the MVC (Model-View-Controller) application pattern. If you're one of those developers, or even if you're just curious, this book is for you.

We've worked hard to make sure that this book is valuable for developers who are experienced with ASP.NET MVC, as well. Throughout the book, we explain how things are designed and how best to use them. We've added in-depth coverage of new features, including a greatly expanded chapter on Routing to cover the new Attribute Routing feature in this release. We've updated the NuGet Gallery case study in the final chapter (explaining how the NuGet development team build and run a real-world, high-volume ASP.NET MVC website) with some interesting lessons learned, directly from the development team. Finally, there's a new chapter from K. Scott Allen explaining how to build Single Page Applications with AngularJS.

How This Book Is Structured

This book is divided into two very broad sections, each comprising several chapters. The first six chapters are concerned with introducing the MVC pattern and how ASP.NET MVC implements that pattern.

  • Chapter 1, “Getting Started,” helps you get started with ASP.NET MVC 5 development. It explains what ASP.NET MVC is and how ASP.NET MVC 5 fits in with the previous releases. Then, after making sure you have the correct software installed, you'll begin creating a new ASP.NET MVC 5 application.
  • Chapter 2, “Controllers,” explains the basics of controllers and actions. You'll start with some very basic “hello world” examples, and then build up to pull information from the URL and return it to the screen.
  • Chapter 3, “Views,” explains how to use view templates to control the visual representation of the output from your controller actions. You'll learn all about the Razor view engine, including syntax and features to help keep your views organized and consistent.
  • Chapter 4, “Models,” teaches you how to use models to pass information from controller to view and how to integrate your model with a database (using Code-First development with Entity Framework).
  • Chapter 5, “Forms and HTML Helpers,” dives deeper into editing scenarios, explaining how forms are handled in ASP.NET MVC. You'll also learn how to use HTML helpers to keep your views lean.
  • Chapter 6, “Data Annotations and Validation,” explains how to use attributes to define rules for how your models will be displayed, edited, and validated.

The following ten chapters build on this foundation, introducing some more advanced concepts and applications.

  • Chapter 7, “Membership, Authorization, and Security,” teaches you how to secure your ASP.NET MVC application, pointing out common security pitfalls and how you can avoid them. You'll learn how to leverage the ASP.NET membership and authorization features within ASP.NET MVC applications to control access, and learn important information about the new ASP.NET Identity system.
  • Chapter 8, “Ajax,” covers Ajax applications within ASP.NET MVC applications, with special emphasis on jQuery and jQuery plug-ins. You'll learn how to use ASP.NET MVC's Ajax helpers and how to work effectively with the jQuery-powered validation system.
  • Chapter 9, “Routing,” digs deep into the routing system that manages how URLs are mapped to controller actions. This chapter explains both Traditional Routes and the new Attribute Routes, shows how to use them together, and explains how to choose when to use each.
  • Chapter 10, “NuGet,” introduces you to the NuGet package management system. You'll learn how it relates to ASP.NET MVC, how to install it, and how to use it to install, update, and create new packages.
  • Chapter 11, “ASP.NET Web API,” shows how to create HTTP services using the new ASP.NET Web API.
  • Chapter 12, “Single Page Applications with AngularJS,” teaches you how to combine your MVC and Web API skills with the popular new AngularJS library to create Single Page Applications with a fun “At The Movies” sample application.
  • Chapter 13, “Dependency Injection,” explains dependency injection and shows how you can leverage it in your applications.
  • Chapter 14, “Unit Testing,” teaches you how to practice test-driven development in your ASP.NET applications, offering helpful tips on how to write effective tests.
  • Chapter 15, “Extending MVC,” dives into the extensibility points in ASP.NET MVC, showing how you can extend the framework to fit your specific needs.
  • Chapter 16, “Advanced Topics,” looks at advanced topics that might have blown your mind before reading the first 15 chapters of the book. It covers sophisticated scenarios in Razor, scaffolding, routing, templating, and controllers.
  • Chapter 17, “Real-World ASP.NET MVC: Building the NuGet.org Website,” puts everything in perspective with a case study covering the NuGet Gallery website (http://nuget.org). You'll see how some top ASP.NET developers handled things like testing, membership, deployment, and data migration when they needed to build a high-performance site on ASP.NET MVC.

What You Need to Use This Book

To use ASP.NET MVC 5, you'll probably want a copy of Visual Studio. You can use Microsoft Visual Studio Express 2013 for Web or any of the paid versions of Visual Studio 2013 (such as Visual Studio 2013 Professional). Visual Studio 2013 includes ASP.NET MVC 5. Visual Studio and Visual Studio Express are available from the following locations:

You can also use ASP.NET MVC 5 with Visual Studio 2012. This is included as part of an update for ASP.NET and Web Tools for Visual Studio 2012 available at the following location:

Chapter 1 reviews the software requirements in depth, showing how to get everything set up on both your development and server machines.

Conventions

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

As for styles in the text:

  • We italicize new terms and important words when we introduce them.
  • We show keyboard strokes like this: Ctrl+A.
  • We show filenames, URLs, and code within the text like so: persistence.properties.
  • We present code in two different ways:
We use a monofont type with no highlighting for most code examples.
We use bold to emphasize code that is particularly important in the present
context or to show changes from a previous code snippet.

Source Code

Throughout the book you'll notice places where we suggest that you install a NuGet package to try out some sample code.

Install-Package SomePackageName

NuGet is a package manager for .NET and Visual Studio written by the Outercurve Foundation and incorporated by Microsoft into ASP.NET MVC.

Rather than having to search around for ZIP files on the Wrox website for source code samples, you can use NuGet to easily add these files into an ASP.NET MVC application from the convenience of Visual Studio. We think this will make it much easier and painless to try out the samples. Chapter 10 explains the NuGet system in greater detail.

Some chapters use examples that require an entire Visual Studio project, which is more easily distributed as a ZIP file. Source code for these chapters is available at http://www.wrox.com/go/proaspnetmvc5.

If you would like to download the sample NuGet packages for later use without an Internet connection, they are also available for download at http://www.wrox.com/go/proaspnetmvc5.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list, including links to each book's errata, is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot “your” error on the Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.
  2. Read the terms of use and click Agree.
  3. Complete the required information to join, as well as any optional information you wish to provide, and click Submit.
  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.133.160