Tuesday, August 13, 2013

Book Review: Pro ASP.NET MVC 4

It's been a while since my last book review, and there are a couple of reasons for that. First, I've been really busy this summer (between speaking engagements and producing 2 Pluralsight courses). And second, because I picked a 700 page book as my next read: Pro ASP.NET MVC 4 by Adam Freeman (Amazon link). The good news is that this was a very good read.

Two Parts
I really like the layout of this book.  It's split into two primary parts.

Part 1 covers the first 300 pages: Introducing ASP.NET MVC 4.  After some introductory chapters (about the MVC pattern, the Razor view engine, and some other tools), Freeman leads us through the process of building an on-line store. During each of these steps, more and more features are explored through the code. This includes things like strongly-typed views, controllers and actions, routing, dependency injection, validation, and security.

These are all "just enough" explanation to get the application to do what we need it to do. This seems like a very relevant example, and I found it helpful to follow along (sometimes typing things in and sometimes just going through the code for the completed project -- although I'll admit to having a run-in with Entity Framework not behaving as I expected it to).

Part 2 is the rest of the book and dives into the details. This makes for an excellent reference and covers pretty much all of the topics: URL Routing, Controllers, Actions, Filters, Views, Helper Methods, Model Binding, Model Validation, and Bundles.

Each of these chapters starts out by looking at the standard "in-the-box" functionality and then goes on to show how you can either customize the behavior or completely replace it with your own objects. Another thing I like is relevant warnings. For example, there may be a section that shows how to put validation into the Controller, but then emphasizes that it probably doesn't belong there; it really belongs in the Model itself or through custom model binding (in order to preserve the separation of concerns recommended by the MVC pattern).

Some Complaints (not mine)
I want to address some complaints that have shown up in some reviews.  But first, we need a little history. I own Pro ASP.NET MVC 2 Framework by Steven Sanderson. This is the 2nd edition of this same book.

[Editor's Note: I actually did a review of this book in 2011: Book Review: Pro ASP.NET MVC 2 Framework]

Next comes, Pro ASP.NET MVC 3 Framework by Steven Sanderson and Adam Freeman. This is the 3rd edition (which I do not have). There were some complaints that the 2nd and 3rd editions had much of the same material and didn't really show the differences in the versions. Personally, I don't have a problem with that. I see this as a reference for whatever current version is referred to. There are other references to see "What's New in MVC 3" or whatever.

Pro ASP.NET MVC 4 by Adam Freeman (the book we're looking at here) is the 4th edition. This has a lot of duplicated information from previous editions (the Sports Store example is the same example as was used in the MVC 2 book, but with some obvious updates for the new features). As mentioned above, I don't see the duplication as a drawback -- this is a 700 page reference book.

A Few Quirks
With that said, there are a few quirks to the book that are minorly distracting. This is to be expected in any technical book of this size; however, since this is the 4th edition, I would have hoped that more of these would be worked out.

One strange thing is that it looks like there was a search-and-replace done for several words to facilitate the diagrams and code samples.  For example, in Chapter 16, there is a sentence with the phrase "...which isn't suiTable 16-for all action methods."  I'm sure this should read "...which isn't suitable for all action methods", but the word "table" was replaced with "Table 16-".  This also happened with "figure" as in "... you can conFigure 17-the settings of the default factory..."

Another quirk has to do with the history of the book. As mentioned above, the 3rd edition was co-authored by Adam Freeman and Steven Sanderson. A few vestiges still exist in the 4th edition. For example, there are a few places that say, "We both agree that..." which seems a little strange if you don't know the history of the book. In addition, other books by both Freeman and Sanderson are referenced for more details. Again, it seems a little strange based on the "voice" of the author.

But none of these items would keep me from recommending this book.

Wrap Up
Pro ASP.NET MVC 4 is a complete reference of the MVC framework. I really like the practical walk-through example that takes up Part 1 of the book. And I also like the deeper dives into each feature that is covered in Part 2. It's nice to know that I can replace the view engine if I really want to (although I really don't see that happening for me).

I'm a big fan of ASP.NET MVC (especially since I spent so much time working/fighting with WebForms). It's nice to see that many of the features (such as URL Routing and Script Bundling) are making their way into the base ASP.NET libraries so that we can use them regardless of how we build our websites.

In the near future, I need to revamp my website. ASP.NET MVC is definitely a contender technology. But I may simply use it as a framework to deploy a mainly HTML/JavaScript site. We'll see what happens. One of the big challenges is to create some "pretty" URLs without breaking any of the existing links that I have scattered across the internet.

But back on topic, if you need a reference for ASP.NET MVC, I would definitely recommend this book.

Happy Coding!


  1. Hi Jeremy, do you think this book will still valid and useful when the ASP.NET MVC 5 coming out?


    1. My first reaction is "yes, it is still valid". ASP.NET MVC version updates are generally new features, but the core concepts stay the same. There have been a few "game changers" (like the adoption of the Razor view engine), but it's generally additions rather than replacements.

      The big things with ASP.NET MVC are things like routing, controllers and actions, views, model binding, validation, etc. Those core concepts will (most likely) not change, and so the content of this book will remain relevant (just missing the new stuff).

      I really like Apress books (I've had a good experience with them on a number of topics). One downside, though, is that the "new version" books are generally not available for several months after the technology has been released. The upside, however, is that the books are not rushed out based on beta versions, and they generally have very solid information about the shipping technology.


  2. Thank for the response Jeremy, so the book could be still valid.
    Next time, could you post a photo of your IT bookshelf? I'm curious to see all these interesting books ;-)


    1. While I do technically have an IT bookshelf (3 shelves, actually), most of my books are in stacks around my house. I have a partial listing (about 40 books) on my website: http://www.jeremybytes.com/Bookshelf.aspx

    2. How is your approach to these titles? Do you read the book entirely, from start to end? Do you test the proposed examples of code?
      Thanks a lot.


    3. Most books I read cover-to-cover. As far as typing along with examples, it really depends on how "hands on" I want to be. For example, "Learning WCF" by Michele Leroux Bustamante includes a ton of labs. I went through each of these when I first read the book several years ago. For "Pro ASP.NET MVC 4", I typed in most of the SportsStore sample, but didn't go step-by-step through the rest of the sample projects (the later samples had more detail than I would use in the near future, so I just read through them).

      Different people learn different ways. I absorb book information pretty easily. If a project or problem catches my eye, then I'll type in the sample code to try it out myself. And sometimes I'll create my own test project to try something out even if there isn't an explicit sample.


    4. Perfect, thank you so much Jeremy. Very detailed.


  3. I'm reading this book now and I agree with you in almost everything you say.

    Very good book. Interesting post.