---
title: "How routing works in ASP.NET MVC4"  
description: "How routing works in ASP.NET MVC4"  
author: "Anonymous User"  
published: 2014-09-29  
updated: 2014-09-29  
canonical: https://www.mindstick.com/forum/2284/how-routing-works-in-asp-dot-net-mvc4  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# How routing works in ASP.NET MVC4

I'm developing an [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) MVC4 [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and I'm new. I have two MapRoutes for routing.

```
routes.MapRoute("Char",                 "ABC/Alpha/{number1}",                  defaults: new { Controller = "ABC", action = "Alpha" });            routes.MapRoute(            name: "Default",            url: "{controller}/{action}/{id}",            defaults: new { controller = "Home", action = "Index",  id=UrlParameter.Optional }        );
```

I didn't assign any [default value](https://www.mindstick.com/forum/2035/default-value-when-using-singleordefault) to the number1 in the MapRoutes. But I know it is mandatory because it is in the [URL](https://www.mindstick.com/forum/436/url-redirection) path.

If I didn't provide any [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) in the url (when I run the app), I should get an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) but I didn't.

Can [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept)?

## Replies

### Reply by Sumit Kesarwani

Hi Pravesh, \

The Route path is checked from top to bottom, so in the first case

{Controller}/{Action}/{ID}

is passed by you (mention the id is must here) so the First routepath works

but Magic you was expecting the second case to throw an error, and it should have because if your Action is like

```
public ActionResult ActionName(int id){//some Code}
```

then for sure it would have thrown error like Action

"Cannot convert null to 'int' because it is a non-nullable [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) type"

and i'm Pretty sure your Action will be having either

```
 public ActionResult(int? id) {//Some Code here}or Public ActionResult(){//Some Code here }
```


---

Original Source: https://www.mindstick.com/forum/2284/how-routing-works-in-asp-dot-net-mvc4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
