These are some of the Very Important Questions that you come across in your ASP.NET MVC programming life. mvc interview questions and answers:

1. How to set default route to an Area in ASP.NET MVC?

You need to add DataToken to Default Route, in order to make your area as default route in route.config. for eg:- You have seperate area for login related files and want to be your default route during your application startup.

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

2.What are the return types of controller action methods?


3.What are Filters in MVC?

In MVC,sometimes we need to perform action before or after particular method or operation. Types of Filters:

4.What are action filters?

These are special attributes which can be applied to either a controller or action methods.It can be executed before and after controller action executes.

5.What are different types of action filters?


6.What is Authorize? Give an example.?

It allows only authorize users to login to the application. For non authorized user , it goes to login page.

        public ActionResult Index()
        ViewBag.Message = "This page is viewed only by authorized user";
        return View();


7.What is Routing? What are the 3 segments of Routing?

Routing helps you to define the URL structure and map the URL with the controller.Routing happens on the basis of URL pattern
The 3 segments of routing are:
Controller name
Action method name
Please see in Route.config file of your mvc application.

8.How can we maintain session in ASP.NET MVC?

SESSION can be maintained in MVC in 3 ways.

9.What is Viewdata?

It is useful for transfering data from controller to is again a keyvalue pair.

10.What is ViewBag?

Viewbag is useful when you want to transfer data from controller to view.The viewbag is dynamic property of controllerbase class

11.What is Tempdata?

It is again a key value pair.It is used when data is to be used in two subsequent request.It can be between 2 actions or 2 controllers.You cant get the tempdate value in 3 rd request,