Programming Razor by Jess Chadwick (O'Reilly) is a short book at only 99 pages, but it is long enough to provide the information that I was looking for. The book covers using Razor (a web templating syntax) with ASP.NET MVC and WebMatrix. My background: I've done some ASP.NET MVC programming (with the Web Forms view engine) and wanted to get started using the Razor view engine. Note: I got this book for "free" as a user group raffle prize, so I did not pay the cover price (just the price of the raffle tickets).
This book assumes that you are familiar with the development environments (WebMatrix and ASP.NET MVC). It only covers how Razor can be used with these tools and does not give you an introduction to the tools themselves. Again, this is what I was looking for -- how to use Razor syntax.
The parts I found most interesting were in the introduction. This chapter shows how you (as the developer) mix HTML markup with C# (or VB) code to create your web pages. The introduction describes how the Razor parser figures out which parts are markup and which parts are code. It also shows how to give the Razor parser hints on differentiating the markup and code in areas that may be ambiguous. This really gave me the information that I needed to move forward with Razor.
The next two chapters were about using Razor with WebMatrix to build a blog. Fortunately, I had just attended a user group where Alice Pang presented WebMatrix (Alice is a WebMatrix Technical Evangelist for Microsoft). Before that session, I really didn't know what WebMatrix was for or how to use it. If you are interested in WebMatrix, Alice's blog is a great place to get started: http://blogs.msdn.com/b/alicerp/.
With that said, unfortunately, the examples in Programming Razor are a bit of a mess. I tried to follow along with the blog sample in WebMatrix and ran into some issues once the database portions hit. The book does not give enough information about the database fields; it shows a screenshot of the table column definitions, but not the details. This table definition has 5 columns (all of them non-nullable), yet the SQL in the code only populates 3 of the columns. There is a separate code-snippet that shows how to make sure one of the other columns is populated, but this is never incorporated into the main code samples. I was hoping to be able to follow the code samples to build a working (simple) app but was unable to. I also had some build issues here; if I was more familiar with WebMatrix, I may have been able to troubleshoot my way out of this. After this bit of frustration, I did not try to follow any further code samples.
The next chapter is about using Razor with ASP.NET MVC 3. This chapter walked through the steps of building blog pages similar to the WebMatrix sample. I came across some inconsistencies in the code samples in this chapter as well. For example, there were simple code blocks described and the sample would include code that was not described until the following section. Although I did not follow along with the code samples, I could see the inconsistencies that cropped up.
The final two chapters cover the Razor API and Advanced Techniques. I must admit that I sort of skimmed through these chapters. I was more interested in the basics of Razor which were described in the previous chapters, and not so much on how I can pre-compile my templates or extend the default Razor view classes.
So, overall, I did get the information that I was looking for from Programming Razor, however, I am very disappointed with the quality of the code samples. Had I paid full price for this ($19.99), I would have been rather upset. With that said, had I gotten the book for $7 or $8, I probably would have been satisfied with the value. I think the book does have value, and I hope that there is a version with more consistent sample code available in the future.