Why do we have to specify the defaults for the default route?
This is a normal default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Why can't I just do this:
routes.MapRoute(
name: "Default",
url: "Home/Index/{id}",
defaults: new {id = UrlParameter.Optional }
);
I already specified the action and controller but when I use this way, I get an error. Does anyone know why you have to specify the action and controller in the default
route?
Without a default set of parameters, how is routing supposed to know where to send this URL?
/
The defaults let you do that URL, so it knows to use the 'Home' controller's 'Index' method.
Or:
/Articles
In this case, the 'Index' action of the 'Articles' controller would be called. Without those defaults, again, routing has no way to know what to do.