Convention-based routing
The routing engine is responsible for mapping the incoming requests to the appropriate action method of the controller.
In the Configure
method of the Startup
class, we have mapped the following route:
app.UseMvc(routes => { routes.MapRoute(name: "default", template: "{controller=Employee}/{action=Index}/{id?}"); });
The MapRoute
method has two parameters:
name
: This represents the name of the route as we could configure multiple routes for the same application.template
: This signifies the actual configuration for the route. There are three parts to this configuration value. As we are supplying default parameters, if the values are not passed, it will take the default parameter values.{controller=Employee}
: The first value acts as the name of the controller and we use theEmployee
controller as the default controller when the controller value is not available in the URL.{action=Index}
: TheIndex
action method...