MVC Interview Questions
MVC Interview Questions
com/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MVC is a software architecture pattern for developing web application. It is handled by three
objects Model-View-Controller.
In an MVC model,
• Model- It represents the application data domain. In other words applications business
logic is contained within the model and is responsible for maintaining data
• View- It represents the user interface, with which the end users communicates. 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 choose a view to render that display
the user interface. The user input logic is contained with-in the controller
• View Result
• Javascript Result
• Redirect Result
• Json Result
• Content Result
5) Mention what is the difference between adding routes, to a webform application and an
MVC application?
• 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 part of your project that makes project less development
and maintenance cost
• MVC makes your project more systematic
• 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
Advantages Disadvantages
• It represents clear separation • The model pattern is little
between business logic and complex
presentation logic • Inefficiency of data access in
• Each MVC object has different view
responsibilities • With modern user interface, it is
• The development progresses in difficult to use MVC
parallel • You need multiple programmers
• Easy to manage and maintain for parallel development
• All classes and object are • Multiple technologies knowledge
independent of each other is required
In MVC “ ActionFilters” help you to execute logic while MVC action is executed or its executing.
12) Explain what are the steps for the execution of an MVC project?
13) Explain what is routing? What are the three segments for routing is important?
Routing helps you to decide a URL structure and map the URL with the Controller.
• ControllerName
• ActionMethodName
• Parameter
15) Explain using hyperlink how you can navigate from one view to other 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.
Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.
17) 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 other
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
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.
• Ajax libraries
• Jquery
In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.
22) Explain what is the difference between View and Partial View?
In MVC, there are twelve types of results in MVC where “ActionResult” class is the main class
while the 11 are their sub-types
• ViewResult
• PartialViewResult
• EmptyResult
• RedirectResult
• RedirectToRouteResult
• JsonResult
• JavaScriptResult
• ContentResult
• FileContentResult
• FileStreamResult
• FilePathResult
All public methods of a controller class are treated as the action method if you want to prevent
this default method then you have to assign the public method with NonActionAttribute.
26) Mention the order of the filters that get executed, if the multiple filters are implemented?
• Authorization filters
• Action filters
• Response filters
• Exception filters
28) Mention what are the file extensions for razor views?
29) Mention what are the two ways for adding constraints to a route?
• As the code is moved behind a separate class file, you can use the code to a great extent
• As behind code is simply moved to.NET class, it is possible to automate UI testing. This
gives an opportunity to automate manual testing and write unit tests.
https://www.guru99.com/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Guru99 Provides FREE ONLINE TUTORIAL on Various courses like
Project
Test Management Business Analyst Ethical Hacking PMP
Management
Software
Jenkins Agile Testing RPA JUnit
Engineering