Confusion on MVC routes

advertisements

What is the problem below?

    routes.MapRoute(
         "Default2", // Route name
         "{controller}/{action}/{id}", // URL with parameters
         new { controller = "Home", action = "Index", id = "test" } // Parameter defaults
     );

    routes.MapRoute(
         "Default1", // Route name
         "{controller}/{action}/{name}", // URL with parameters
         new { controller = "Home", action = "Report", name = "" } // Parameter defaults
     );

When I navigate to /home/index "id" parameter takes the default value of "test" but when I navigate to home/report the name parameter is null.

In short, if the route definition is the first in the route table, then the parameter takes its default value. But the others below don't.


These two routes {controller}/{action}/{id} and {controller}/{action}/{name} are ambiguous. It cannot distinguish between /home/index/id and /home/report/abc, it is always the first route in the route definition which will be caught because in the second case it thinks that id = "abc".