views:

41

answers:

3

In my AccountController class I have the following:

public ActionResult Verification(string userGuid)
{

    Debug.WriteLine(userGuid);
...

In my global.asax I have:

routes.MapRoute(
    "AccountVerification", 
    "{controller}/{action}/{userGuid}", 
    new { controller = "Account", action = "Verification", userGuid = UrlParameter.Optional }
);

When I go to http://localhost/Account/Verification/123 ... theres no debug output... its not recognizing the parameter - which is my problem. Not sure what I'm missing.

I do want this parameter to be optional... if its not set then I return a different view.

Edit: When I place a Debug.WriteLine("hello world"); in the Verification function, it does output it so the routing appears to go to the correct function.

Edit Again: The default controller is still present but I wouldn't think it would hit that route since it uses a different controller / action

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
+2  A: 

The route you have given us should match this - what other routes have you defined above it? It may be being picked up by a different route.

David M
Not sure how it would be picked up by another route. Theres no other actions defined in my AccountController with the name Verification. I can confirm that it is hitting my Verification function, just outputs an empty string for userGuid.
Chris Klepeis
Have you left the default route in, which is {controller}/{action}/{id}, and which would map your "123" to an "id" parameters? If so, because it is not defined as a parameter to your method, it will just pass "123" it in in the route data and leave userGuid blank.
David M
Yes, the default one is in there as well.. but since its defined to use a different controller (Home) and action (Index) I would have thought it would not use this.
Chris Klepeis
No, these are only the defaults that are specified - if it's above the one you have defined, it will pick up everything matching your pattern. Replace {controller} and {action} with the hard-coded values Account and Verification, and move your route above the default one. It will then pick up first, and everything else will trickle down to the default.
David M
Worked! thanks!
Chris Klepeis
+1  A: 

The RouteDegguer will help identify which routes are being picked up.

gnome
A: 

Put this definition at the top and see if it still doesn't work. first step to debugging routes

BritishDeveloper
Did you include code? Please format it so I can see it.
Chris Klepeis
No i didn't. I mean't put your routing definition above any others you have (if you have any). This has helped me debug a problem a few times
BritishDeveloper