Model-View-Controller Interview Questions and Answers

Explain what a is Model-View-Controller.

MVC is a software architecture pattern for developing web applications. It is handled by three objects Model-View-Controller.

Mention what does Model-View-Controller represents in an MVC application.

In an MVC model,

Model– It represents the application data domain. In other words, application business logic is contained within the model and is responsible for maintaining data

View– It represents the user interface, with which the end users communicate. In short, all the user interface logic is contained within the VIEW

Controller– It is the controller that answers to user actions. Based on the user actions, the respective controller responds within the model and chooses a view to render that display the user interface.  The user input logic is contained within the controller

ADF Online Training

Explain in which assembly the MVC framework is defined.

The MVC framework is defined in the System.Web.Mvc.

List out a few different return types of a controller action method.

View Result

Javascript Result

Redirect Result

JSON Result

Content Result

Mention what is the difference between adding routes, to a webform application and an MVC application.

To add routes to a webform application, we can use the MapPageRoute() method of the RouteCollection class, where adding routes to an MVC application, you can use the MapRoute() method.

Mention what are the two ways to add constraints to a route.

The two methods to add constraints to a route is

Use regular expressions

Use an object that implements the IRouteConstraint Interface

Mention what are the advantages of MVC.

MVC segregates your project into a different segment, and it becomes easy for developers to work on

It is easy to edit or change some parts of your project making the project less development and maintenance cost

MVC makes your project more systematic

Mention what the “beforFilter()”, “beforeRender” and “afterFilter” functions do in Controller.

beforeFilter(): This function is run before every action in the controller. It’s the right place to check for an active session or inspect user permissions.

beforeRender(): This function is called after controller action logic, but before the view is rendered. This function is not often used but may be required If you are calling render() manually before the end of a given action

afterFilter(): This function is called after every controller action, and after rendering is done. It is the last controller method to run

Explain the role of components Presentation, Abstraction, and Control in MVC.

Presentation: It is the visual representation of a specific abstraction within the application

Abstraction: It is the business domain functionality within the application

Control: It is a component that keeps consistency between the abstraction within the system and their presentation to the user in addition to communicating with other controls within the system

Explain the role of “ActionFilters” in MVC.

In MVC “ ActionFilters” help you to execute logic while the MVC action is executed or is executing.

 Explain what are the steps for the execution of an MVC project.

The steps for the execution of an MVC project include

Receive the first request for the application

Performs routing

Creates MVC request handler

Create Controller

Execute Controller

Invoke action

Execute Result

To Learn How to Use Model View Parameters in Looker | GoLogica

Explain what is routing. What are the three segments for routing is important?

Routing helps you to decide on a URL structure and map the URL with the Controller.

The three segments that are important for routing is

ControllerName

ActionMethodName

Parameter

Explain how routing is done in the MVC pattern.

There is a group of routes called the RouteCollection, which consists of registered routes in the application.  The RegisterRoutes method records the routes in this collection.  A route defines a URL pattern and a handler to use if the request matches the pattern. The first parameter of the MapRoute method is the name of the route. The second parameter will be the pattern to which the URL matches.  The third parameter might be the default values for the placeholders if they are not determined.

 Explain using hyperlinks how you can navigate from one view to another view.

By using “ActionLink” method as shown in the below code. The below code will make a simple URL which help to navigate to the “Home” controller and invoke the “GotoHome” action.

Collapse / Copy Code

<%= Html.ActionLink(“Home”, “Gotohome”) %>

Mention how can maintain a session in MVC.

Session can be maintained in MVC in three ways tempdata, viewdata, and viewbag.

Mention what is the difference between Temp data, View, and View Bag.

Temp data: It helps to maintain data when you shift from one controller to another controller.

View data: It helps to maintain data when you move from controller to view

View Bag: It’s a dynamic wrapper around view data

What is the partial view in MVC?

Partial view in MVC renders a portion of view content. It is helpful in reducing code duplication. In simple terms, partial view allows to render a view within the parent view.

Explain how you can implement Ajax in MVC.

In Ajax, MVC can be implemented in two ways

Ajax libraries

Jquery

.Net MVC Training

Mention what is the difference between “ActionResult” and “ViewResult”?

“ActionResult” is an abstract class while “ViewResult” is derived from “the AbstractResult” class.  “ActionResult” has several derived classes like “JsonResult”, “FileStreamResult” and “ViewResult”.

“ActionResult” is best if you are deriving different types of views dynamically.

Explain how you can send the result back in JSON format in MVC.

In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.

Share with:


March 6, 2025