Introduction to routing
The routing engine is responsible for getting the incoming request and routing that request to the appropriate Controller based on the URL pattern. We can configure the routing engine so that it can choose the appropriate controller based on the relevant information.
By convention, ASP.NET MVC follows this pattern: Controller/Action/Id.
If the user types the URL http://yourwebsite.com/Hello/Greeting/1
, the routing engine selects the Hello controller
class and Greeting action
method within the HelloController
, and passes the Id
value as 1
. You can give default values to some of the parameters and make some of the parameters optional.
The following is the sample configuration:
The template: "{controller=Hello}/{action=Greeting}/{id?}");
In the preceding configuration, we are giving three instructions to the routing engine:
- Use the routing pattern
controller/action/id
. - Use the default values
Hello
andGreeting
for thecontroller
andaction
respectively, if the...