« writeFile service for webMethods Integration Server | Main | Simple logging for Integration Server »
Tuesday
28Apr2009

NerdDinner

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.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

Hey Rob,
Good stuff. I've just started messing around with ASP.NET MVC stuff as well. There is another walk through on Microsoft's ASP.NET site that is pretty good for getting into it quick, it's located here - ASP.NET. Your post is going to be really helpful when I dive into the nerd dinner.

Microsoft seems to be doing a lot more with REST rather than SOAP. I bring this up because they are using that in some of their MVC examples. I've noticed it cropping up in some of their other stuff as well. I'm curious what your take on that is. I went through some of their REST examples and I found them to be a bit more involved than just working with a Web Service that was using SOAP.

What do you think? Are they starting to distance themselves from the more traditional Web Services and move to Restful services?

April 29, 2009 | Unregistered CommenterMark Griffin

Thanks for the comments Mark. I had seen the contact management sample along with the others (looks like the asp.net pages have been reworked) and was thinking about walking through the code camp app. It uses NHibernate which is what is planned for a possible upcoming project. LINQ is nice to use so it'll be good to see how NHibernate compares.

The REST trend from MS would seem to mirror the overall trend. REST is a hot topic. I'm not sure that they are backing off of SOAP as much as just paying attention to REST.

REST and SOAP are not on the same conceptual plane, IMO. A RESTful approach is more involved than is a SOAPy one. I'm still trying to get a more ingrained feel for how to recognize REST as Fielding intended and distinguishing that from REST as "technology" as many seemed to have morphed it.

April 29, 2009 | Registered Commenterreamon

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>