---
title: "What is routing in MVC?"  
description: "What is routing in MVC?"  
author: "Anonymous User"  
published: 2019-10-15  
updated: 2020-09-17  
canonical: https://www.mindstick.com/interview/33658/what-is-routing-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc", "mvc", "mvc4"]  
reading_time: 2 minutes  

---

# What is routing in MVC?

Routing helps you to define a URL structure and map the URL with the controller.

Let us try to understand this with an example, - when we want that when a user types "http: // localhost / View / ViewCustomer /", it goes to the "Customer" controller and the DisplayCustomer action Invites you. This is defined by adding an entry into the routes collection using the map_route function. Below is the underlined code which shows how the URL structure and mapping with controller and action are defined.

```
routes.MapRoute(
               "View", // Route name
               "View/ViewCustomer/{id}", // URL with parameters
               new { controller = "Customer", action = "DisplayCustomer",
id = UrlParameter.Optional }); // Parameter defaults   
```

And the route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.\

## Answers

### Answer by Anonymous User

Routing helps you to define a URL structure and map the URL with the controller.

Let us try to understand this with an example, - when we want that when a user types "http: // localhost / View / ViewCustomer /", it goes to the "Customer" controller and the DisplayCustomer action Invites you. This is defined by adding an entry into the routes collection using the map_route function. Below is the underlined code which shows how the URL structure and mapping with controller and action are defined.

```
routes.MapRoute(
               "View", // Route name
               "View/ViewCustomer/{id}", // URL with parameters
               new { controller = "Customer", action = "DisplayCustomer",
id = UrlParameter.Optional }); // Parameter defaults   
```

And the route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.\


---

Original Source: https://www.mindstick.com/interview/33658/what-is-routing-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
