The Default Route

When you press to debug an MVC application you will see the URL is simplified and easy to understand and can use as a navigation as well. For an example when you click on the “About” link of the default MVC application you the URL visible will look like this.


As you see after the domain name (in this case the localhost with the port number) it says Home and the forward slash and About. So it looks like you might have a Home folder and then About folder and there is no file name given end of the URL (ex: About.aspx). But you have a page displayed. If you wonder how this is possible, the trick is under routing.

OK, where this is handled?

Click on the Solution Explorer and expand your web project (in this example WebApplication5) and expand App_Start folder. Double click on the file, named RouteConfig.cs


Now scroll down to the code that looks like this

From line 7 to 11 you will see the route collection is being added. This is called the “Default Route”. It has three parameters

name: Name of the the route, in this case its “Default”

url: Which is the pattern of the URL that this route will create. {controller} represent the actual Controller of the MVC application. In this example its the HomeController and {action} represents the action within the controller again in this one its the About action within the HomeController and {id} is the parameter that takes in to an action method with in the controller.

defaults: These are the defaults values to replace above url pattern. And its self explainary. And says id parameter is optional.

Good Day !!! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *