[Book Review] ASP.NET MVC 2 Cookbook

 A short while back I was asked if I would be interested in reviewing Packt Publishing's ASP.NET MVC 2 Cookbook and since it was right up my alley, I accepted. So over the past 6 weeks or so, I've been reading the book as I've gotten a chance. While the book covers ASP.NET MVC 2, most of it is still quite relevant to MVC 3. If you have already gotten started with ASP.NET MVC, but are not a power user, this book is a must have in your collection. I've been using ASP.NET MVC since Guthrie first announced it and I learned a few tricks as well.


It can be said that Cookbook formatted  books are becoming more popular with readers, especially those already semi-familiar with a subject. I'm a fan of them also as I feel they cut out the basic bits that a true beginner would need and start off at an intermediate level. The book covers the following:

  • Working with Views
  • Working with Actions
  • Routing
  • Master Pages
  • Working with Data in your View
  • Forms
  • Simplification of Complex Applications
  • Validation
  • Data Access
  • Application, Session, Cookies, and Caching

What I liked about the book was the use of a Dependency Injection framework, in this case StructureMap, to help ease testibility. The authors were even careful to point out that they were using it for testibility, not to switch out implementation later. What I did not like was the heavy use of ViewData within the book. Personally I try to avoid the use of ViewData unless absolutely necessary, preferring to use Strongly Typed views instead. Another thing I would've liked to seen is the use of ViewModels and FormModels. ViewModels are used to send only the data needed to the view. This does not mean sending a fully populated object graph, only the pieces of the graph that are needed. FormModels are used to deliver the data back from the view. You use this to populate new entities, load and modify existing entities, and for Validation.

Hidden Gem

The hidden gem of this book is a little known project named NBuilder. I had not heard of this project until shortly before reading the book, thanks to a tweet from a friend. The book makes heavy use of NBuilder in it's samples, especially in mocking. If you are not using NBuilder in your current testing, I would highly suggest you take a look at it. It makes adding sample data extremely simple.

Overall I really liked the book and thinks it is worthy of a spot on your bookshelf if you are working with ASP.NET MVC. Hopefully the authors will update the book to reflect changes in MVC 3.

No Comments