Confusion about MVC Routes
Posted
by yang
on Stack Overflow
See other posts from Stack Overflow
or by yang
Published on 2010-04-18T11:15:59Z
Indexed on
2010/04/18
11:23 UTC
Read the original article
Hit count: 356
asp.net-mvc
|routes
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.
© Stack Overflow or respective owner