views:

6720

answers:

4
+3  Q: 

ASP.NET MVC routes

I need help with this route map

routes.MapRoute("Blog_Archive", 
                "Blog/Archive/{year}/{month}/{day}",
                new { 
                      controller = "Blog",
                      action = "archive",
                      year = "",
                      month = "",
                      day = "",
                      page = 0
                    });

When I call http://localhost:5060/blog/Archive/2008/11, it picks up the year and month and sends it to the controller. But when I try http://localhost:5060/blog/Archive/2008
it sends it to the controller but the year parameter is null and so are all the other parameters.

+6  A: 

Do you have any other Route for Blog/Archive/{something}?

Use the Routing Debugger to see which route actually gets hit, most likely it's not hitting that route.

Michael Stum
Highly recommend the Routing Debugger!
Terry Donaghe
check my respones thank for the help it works now
Subnus
A: 

i can't get the Routing Debugger to work it gives this error

details about exception: System.NullReferenceException: Object reference not set to an instance of an object.

StackTrace:  
[NullReferenceException:

System.NullReferenceException: Object reference not set to an instance of an object.] System.Collections.Generic.Dictionary`2.get_Keys() +17 RouteDebug.DebugHttpHandler.FormatRouteValueDictionary(RouteValueDictionary values) +125 RouteDebug.DebugHttpHandler.ProcessRequest(HttpContext context) +753 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Subnus
Make sure your versions are compatible. What version of MVC are you using?
Terry Donaghe
Can you maybe post your global.asax? Route Debugger works fine on MVC Beta for me. Download the Binary, add a Reference to RouteDebug.dll and add this after the "RegisterRoutes": RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
Michael Stum
it works now i was a old version of RouteDebug.dll i had
Subnus
+2  A: 
public static void RegisterRoutes(RouteCollection routes)
 {

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  routes.IgnoreRoute("favicon.ico");

  routes.MapRoute(
   "Blog",
   "Blog/{action}/{id}",
   new
   {
    controller = "Blog",
    action = "show",
    id = ""
   });

  routes.MapRoute("Blog_Archive", "Blog/Archive/{year}/{month}/{day}", 
   new { 
    controller = "Blog",
    action = "archive",
    year = "",
    month = "",
    day = "",
    page =0
   });

  routes.MapRoute(
   "Xfire",                                     
   "Xfire/{action}/{id}",                       
   new
   {
    controller = "Xfire",
    action = "show",
    id = ""
   });

  routes.MapRoute(
   "Photos",                                        
   "Photos/{action}/{id}",                          
   new
   {
    controller = "Photos",
    action = "show",
    id = ""
   });

  routes.MapRoute("About","About",
      new
      {
       controller = "home",
       action = "about"
      });

  routes.MapRoute("Default", "{controller}/{action}/{id}",
      new
      {
          controller = "Blog",
          action = "show",
          id = ""
      });

  routes.MapRoute("Error", "{*url}", new
  {
   controller = "Home",
   action = "Http404"
  ,
  });

 }

found the error

routes.MapRoute("Blog","Blog/{action}/{id}",
                  new {
      controller = "Blog",
                        action = "show",
                        id = ""
                      });

is before

routes.MapRoute("Blog_Archive", "Blog/Archive/{year}/{month}/{day}", 
                  new { 
                        controller = "Blog",
                        action = "archive",
                        year = "",
                        month = "",
                        day = "",
                        page =0
                      });
Subnus
A: 

Subnus, I noticed in your code that you have routes.IgnoreRoute("favicon.ico"); I don't think this is required with MVC 1.0 right because the period is no longer ignored correct?

Mouffette
this question was i regard to the Beta 2 of asp.net mvc and not the now release version of mvc and the question was not about the ignored route
Subnus