.Net Interview Questions and Answers

Search:

5 important ASP.NET MVC routing interview questions

By : Shiv Prasad Koirala | Nov 10th, 2014 | Views : 18469 | Comments : 0 Bookmark and Share

ASP.NET MVC routing is one of favorite topics during MVC interviews. In this article we will try to go through some important questions around MVC routing section. If you are new to MVC and want to start learning you can start from this MVC youtube video



What are routing in MVC?

Routing helps you to define user friendly URL structure and map those URL structure to the controller.

For instance let's say we want that when any user types "http://localhost/View/ViewCustomer/" , it goes to the "Customer" Controller and invokes "DisplayCustomer" action.This is defined by adding an entry in to the "routes" collection using the "maproute" function. Below is the under lined code which shows how the URL structure and mapping with controller and action is defined.



Where is the route mapping code written?

The route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.

Can we map multiple URL's to the same action?

Yes , you can , you just need to make two entries with different key names and specify the same controller and action.

Explain attribute based routing in MVC?


This is a feature introduced in MVC 5. By using the "Route" attribute we can define the URL structure. For example in the below code we have decorated the "GotoAbout" action with the route attribute. The route attribute says that the "GotoAbout" can be invoked using the URL structure "Users/about".



What is the advantage of defining route structures in the code?

Most of the time developers code in the action methods. Developers can see the URL structure right upfront rather than going to the "routeconfig.cs" and see the lengthy codes. For instance in the below code the developer can see right upfront that the "GotoAbout" action can be invoked by four different URL structure.


This is much user friendly as compared to scrolling through the "routeconfig.cs" file and going through the length line of code to figure out which URL structure is mapped to which action




From here you can download 100 ASP.NET MVC interview Ebook from this link http://www.codeproject.com/Articles/556995/MVC-interview-questions-with-answers

 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi