fooberry

Sweetness without context.

Routing Newbie Mistake

April 1st 2010

008So Im a n00b in some areas and it is painful finding this out sometimes. I spent most of the morning trying to figure out why my ASP.Net Web Site application wasnt routing to my MVC controller that is inside of my ASP.Net MVC Area.

Granted, that is a weird setup so there are a lot of things I thought could possibly go wrong. The real reason was embarrassingly obvious, but not embarrassing enough that I wouldnt post it for the world to see.

What do you see wrong with this route:

context.MapRoute(

"Default Route",
"ServerManagement/{controller}/{action}/{id}",
new {   controller = "farms", 
        action = "index"
    });</pre>

Give up? You have to give a default value if you have a placeholder in the route. In this case we have /{id} in the route, but we never a default value for the id. The following route worked fine.

context.MapRoute(
    "Default Route",
    "ServerManagement/{controller}/{action}/{id}",
     new {   controller = "Farms", 
             action = "index", 
             id=""
         });

Lesson learned!

blog comments powered by Disqus