Sprint Planner Helper – Session 20

Posted by Marcus Hammarberg on March 13, 2009
Stats

Today I plan to finish up the last part of the prioritizing of Product Backlog Items (see Session 19). That is TDD the controller and then wrap the GUI.

Let’s go!

Whooa – I ran into some problems with routing. Some problems that took me about two sessions (read: hours) to solve. To not to bore you with details or meaningless posts on me scratching my head, I’ll sum it up in this post.

Here is the layout of the “problem"; I have an Action-method with two parameters:

public ActionResult PrioUp(int productID, int productBacklogItemID)

OK – but how do I create a link to that method? Well by using the Html-helper ActionLink-method of course. You define an anonymous object with the route values. Here is my example:

Html.ActionLink("Prio up""PrioUp", "ProductBacklogItem", new {productID = Model.ID, productBacklogItemID = item.ID}, null);

OK – but here comes the problems. I have no routing-table entry for sending two parameters. And here I was hanging around, trying stuff out, screaming loud, hammering the keyboard. I just don’t get the routing-stuff yet…

So finally I added this routing-table entry, first of the entries:

            // http://localhost/ProductBacklogItem/PrioUp/productId/productBacklogItemID

            // http://localhost/ProductBacklogItem/PrioUp/1001/2

            routes.MapRoute(

                "ProductBacklogPrio",                                       // Name

                "{controller}/{action}/{productId}/{productBacklogItemID}", // Url with parameters

                new {controller = "ProductBacklogItem"},                    // Parameter defaults

                new { productId = @"\d+", productBacklogItemID = @"\d+" }

            );

That worked! I cannot say that I fully understand why since I thought that I tried it… but naming issues and not concentrating well enough.

A few things to note:

  • It has been very helpful to specify an example on how I wanted the URL to look.
  • I had to specify the full URL ({controller}/{action}/{productId}/{productBacklogItemID} to get it to work
  • I skipped default values for productID and productBacklogItemID since that make no sense
  • The final row is a constaint that states that productID and productBacklogItemID should be numeric

These problems and a tip from Christer made me decide to pause this project for a while. There is a new book on ASP.NET MVC coming out soon which contain a tutorial chapter that looks very nice. You can download it here.

I will run through that chapter and hope that it wont take me to long and also that I’ll learn a lot of stuff that come in handy in the Sprint Planner Helper project.

In fact (and this is a secret) I love doing these walkthroughs – feels like I know something very well…

Alright – but now I have a way to prioritize product backlog items up and and down.

See ya in a while.



Published by Marcus Hammarberg on Last updated