Book Image

ASP.NET MVC 1.0 Quickly

By : Maarten Balliauw
Book Image

ASP.NET MVC 1.0 Quickly

By: Maarten Balliauw

Overview of this book

<p>Using WebForms has led to problems for ASP.NET developers, such as low testability and inconsistent code. These problems become increasingly relevant when trying to develop or maintain anything but the simplest web site.<br /><br />This book takes you through the ASP.NET MVC framework to help you simplify and build web applications quickly. With example applications built on best practices and with clear explanations, you will get started in no time.<br /><br />The MVC pattern is widely accepted as one of the best approaches for building modern web applications and Microsoft's new ASP.NET MVC Framework offers a fully supported way for developers to implement MVC in ASP.NET.<br /><br />This book takes you through the essential tasks to create powerful web applications as fast as possible. These essential tasks are explained clearly, with well-structured instructions. The book does not cover every single feature in detail; it provides precise information for you to get started, and takes you through the creation of an example application that covers MVC application design techniques.<br /><br />In addition to helping you write code, this book covers unit testing, to improve the stability and quality of the application you are building. It provides a quick reference to the MOQ framework to aid in unit testing. With this book, you will soon have the skills that will make you an ASP.NET developer to be reckoned with, and you will be creating applications with a speed that will astonish your colleagues and boss!</p>
Table of Contents (18 chapters)
ASP.NET MVC 1.0 Quickly
Credits
About the author
About the reviewers
Preface
ASP.NET MVC Mock Helpers

Preface

Over the years, people have been asking the ASP.NET support team for the ability to develop web applications using a model-view-controller (MVC)architecture. In October 2007, Scott Guthrie presented the first preview of the ASP.NET MVC framework. Ever since, interest in this product has been growing, and many example applications and components have been released on the Internet by enthusiastic bloggers and Microsoft employees.

ASP.NET MVC 1.0 Quickly was written to help people who have a basic knowledge of ASP.NET Webforms to quickly get up-to-speed with developing ASP.NET MVC applications. The book starts by explaining the MVC design pattern, and follows this with a bird's eye-view of what the ASP.NET MVC framework has to offer. After that, each chapter focuses on one aspect of the framework, providing in-depth details of the components that comprise the ASP.NET MVC framework. For each of the concepts explained, a to-the-point example application is provided, demonstrating the theory behind the concept.

By the time you finish this book, you'll be well be on your way to mastering the ASP.NET MVC framework, and will have the confidence to build your own ASP.NET MVC applications.

What this book covers

Chapter 1 describes the MVC software design pattern, and how it can be used in application architecture. We also look at the reason why Microsoft started the ASP.NET framework project, and how it compares with ASP.NET Webforms.

Chapter 2 describes the ASP.NET MVC project template that is installed in Visual Studio. A simple application is built, briefly touching on all of the aspects of the ASP.NET MVC framework.

Chapter 3 describes how interactions with the model are handled through a request/response scenario. A simple application where data is displayed and posted to the web server is built, to demonstrate the concepts described.

Chapter 4 takes us through the components that comprise the ASP.NET MVC framework, covering the request lifecycle and all of the components, including model, view and controller, in depth. You will also take a look at some useful concepts such as action filters and the validation of data.

Chapter 5 describes what ASP.NET routing is, and how it works. We will also take a look at how a URL is transformed into a call to an ASP.NET MVC controller. Next, this chapter shows you how an ASP.NET MVC application can be combined with an ASP.NET Webforms application.

Chapter 6 describes how you can customize and extend the ASP.NET MVC framework. You will learn how to build a control, or so-called partial view, how to create an action filter, and how to create a custom ActionResult. You will even build your own view engine that supports simple HTML markup, completely replacing ASP.NET MVC's default view engine.

Chapter 7 describes how you can use existing ASP.NET features, including master pages, sessions, membership, and internationalization, in the ASP.NET MVC framework. This chapter also shows you how to share data between the ASP.NET MVC and ASP.NET Webforms.

Chapter 8 describes how you can use AJAX in combination with ASP.NET MVC by using two of the most popular AJAX frameworks: ASP.NET AJAX and jQuery. jQuery UI plugins are used to enrich ASP.NET MVC views.

Chapter 9 describes how you can create unit tests for your ASP.NET MVC applications, and explains what mocking is, and how this can help you when creating tests for an ASP.NET MVC application.

Chapter 10 describes how you can deploy and host an ASP.NET MVC application on the Internet Information Server (II6 and IIS7). You'll also see the differences between IIS' integrated mode and classic mode.

Appendix A builds a sample application, CarTrackr—an online software application designed to help you understand and track your fuel usage and kilometers driven. We will zoom in on certain aspects of this application, which will make your development of ASP.NET MVC applications easier and faster.

Appendix B contains source code that assists in testing an ASP.NET MVC application using a mocking framework, as described in Chapter 9 of this book. Source code is provided for use with three different mocking frameworks: RhinoMocks, Moq, and TypeMock.

Appendix C contains links to web sites that provide information and resources related to the ASP.NET MVC framework. It also examines several open source projects that provide additional features.

What you need for this book

No previous experience of the ASP.NET MVC framework is required. Because the ASP.NET MVC framework builds on top of ASP.NET, some previous experience with ASP.NET Webforms is useful in order to quickly catch up with the concepts that exist in ASP.NET Webforms and ASP.NET MVC. An understanding of JavaScript, HTML, and CSS is assumed, as well as an understanding of .NET 3.5 LINQ (Language Integrated Query).

Who this book is for

This book is for web developers with a basic knowledge of ASP.NET and C#, who wish to start using the new ASP.NET MVC framework.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "All the examples in this topic again make use of the Contact class defined earlier."

A block of code is set as follows:

public ActionResult UpdateContact(int id, string name, string email)
{
Contact contact = Contacts.Single(c => c.Id == id);
contact.Name = name;
contact.Email = email;
return RedirectToAction("Index");
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are shown in bold, as in the example below:

container.RegisterType<ICostsRepository, CostsRepository>(
new ContextLifetimeManager<ICostsRepository>());
// Set controller factory
ControllerBuilder.Current.SetControllerFactory(
new UnityControllerFactory(container)

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: " By default, views are located inside the Views | ControllerName project folder ".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to , and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or send an email to .

If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/7542_Code.zip to directly download the example code used in this book.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.