447,253 views 287 on YTPak
843 17

Published on 28 Apr 2013 | over 4 years ago

Text version of the video


All ASP .NET MVC Text Articles

All ASP .NET MVC Slides

ASP.NET MVC Playlist

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video we will discuss about controllers. Please watch Part 3 of MVC tutorial before proceeding. In Part 3, we discussed that, the URL - http://localhost/MVCDemo/Home/Index will invoke Index() function of HomeController class. So, the question is, where is this mapping defined. The mapping is defined in Global.asax. Notice that in Global.asax we have RegisterRoutes() method.

Right click on this method, and select "Go to Definition". Notice the implementation of RegisterRoutes() method in RouteConfig class. This method has got a default route.
public static void RegisterRoutes(RouteCollection routes)

name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

The following URL does not have id. This is not a problem because id is optional in the default route.

Now pass id in the URL as shown below and press enter. Nothing happens.

Change the Index() function in HomeController as shown below.
public string Index(string id)
return "The value of Id = " + id;

Enter the following URL and press enter. We get the output as expected.

In the following URL, 10 is the value for id parameter and we also have a query string "name".

Change the Index() function in HomeController as shown below, to read both the parameter values.
public string Index(string id, string name)
return "The value of Id = " + id + " and Name = " + name;

Just like web forms, you can also use "Request.QueryString"
public string Index(string id)
return "The value of Id = " + id + " and Name = " + Request.QueryString["name"];
Customize Your Hybrid Embed Video Player!

6-digit hexadecimal color code without # symbol.


Report video function is under development.


Loading related videos...