NerdDinner
Tuesday, April 28, 2009 at 11:49AM
reamon in Software Development

I've just completed the NerdDinner sample chapter from the upcoming book Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, and Scott Guthrie. It's been quite enjoyable and very instructive. It's been some time since I did anything in Visual Studio and this was just the thing to get reacquainted with the IDE.

I used MS Visual Web Developer 2008 Express and MS SQL Server Express with Advanced Services to implement the sample. The express editions are great ways to dabble a bit without dropping a bunch of coin on Microsoft.

In working through the sample I changed a few things.

PRG Pattern

The post-redirect-get pattern for web apps is gaining ground but still isn't all that prevalent. The pattern is a natural fit for MVC. The sample uses it--mostly. When errors occurred it still returned a page instead of a redirect which brings back the issues PRG intends to address.

The key to making PRG work in error conditions is saving the error state across the post and get boundary. ASP.NET MVC provides a ModelState object that holds this information. It also provides a TempData object which is associated with the user session. Placing the ModelState object within the TempData table provides a simple way to maintain the error state over the post-redirect-get.

In ASP.NET MVC Best Practices (Part 1) Kazi Manzur provides several tips for robust ASP.NET MVC applications, including using action filters to implement PRG. I used tip 13 to support a redirect on error capability with relative ease.

Paging

The NerdDinner sample uses <<< and >>> links for previous and next page paging of the list of dinners. I like a number list for paging better, such as 1 | 2 | 3 | 4. There are a few samples available on the web, including some that are quite sophisticated that do things like "paging of the pages".  For example, the page navigation bar looks like |< << 6 7 8 9 10 >> >| for the example provided by Jeff Putz at Paging Links in ASP.NET MVC.

I chose to go a simpler route, using the NumericPager class from Rob Conery listed at ASP.NET MVC: Avoiding Tag Soup. Spiffy.

Adding the Map

I ran into some minor issues with the sections of the sample that add the MS Virtual Earth map to the create, edit and details views.

First up was that the map didn't display in the correct location. This was because the sample didn't cover the Site.css changes that are needed. Adding in the CSS entries for #theMap, #dinnerDiv and #mapDiv did the trick. The Site.css file with these (and other) entries can be browsed at nerddinner.codeplex.com.

Next, the details display was pooched after adding the <div> sections to Details.aspx. It looked like this:

Note how the background of what is the "main" <div> does not extend to enclose its children. This appears to be a classic "hasLayout" issue within Internet Explorer as Firefox displays the page correctly. Adding overflow: hidden; to #main within Site.css corrects the issue for IE.

Lastly, pasting the code from the PDF to add the search capability has a couple of problems. The first one is an apparent typo problem with missing end braces/parentheses. The other is that the text does not indicate that script tags referencing the Virtual Earth map control script and the Map.js script are needed within Home/Index.aspx.

Each of these were pretty minor and easily resolved but helped brush the dust off troubleshooting and debugging skills with MS VS.

Membership

Next I plan to tackle providing user roles and allowing any user in the Administrators group to edit any dinner entry. Included in the plan will be pages to manage group definitions and membership within. There is a starter membership project provided by Troy Goode at CodePlex and described at Goode's SquaredRoot blog.

If you're thinking about ASP.NET development I would encourage looking at using ASP.NET MVC. And I'd recommend implementing the NerdDinner sample to gain familiarity with ASP.NET MVC.

Article originally appeared on reamon (http://reamon.squarespace.com/).
See website for complete article licensing information.