MVC Framework Interview Questions & Answers

  1. Question 1. Explain What Is Model-view-controller?

    Answer :

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

  2. Question 2. Mention What Does Model-view-controller Represent In An Mvc Application?

    Answer :

    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

  3. . NET Interview Questions

  4. Question 3. Explain In Which Assembly Is The Mvc Framework Is Defined?

    Answer :

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

  5. Question 4. List Out Few Different Return Types Of A Controller Action Method?

    Answer :

    •View Result
    •Javascript Result
    •Redirect Result
    •Json Result
    •Content Result

  6. Framework7 Tutorial

  7. Question 5. Mention What Is The Difference Between Adding Routes, To A Web Form Application And An Mvc Application?

    Answer :

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

  8. Framework7 Interview Questions

  9. Question 6. Mention What Are The Two Ways To Add Constraints To A Route?

    Answer :

    The two methods to add constraints to a route is
    •Use regular expressions
    •Use an object that implements IRouteConstraint Interface

  10. Question 7. Mention What Is The Advantages Of Mvc?

    Answer :

    •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.

  11. Unittest Framework Tutorial
    Java collections framework Interview Questions

  12. Question 8. Mention What “beforfilter()”,“beforerender” And “afterfilter” Functions Do In Controller?

    Answer :

    •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.

  13. Question 9. Explain The Role Of Components Presentation, Abstraction And Control In Mvc?

    Answer :

    •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

  14. Microsoft Solutions Framework (MSF) Interview Questions

  15. Question 10. Mention The Advantages And Disadvantages Of Mvc Model?

    Answer :

    Advantages:

    • It represents clear separation between business logic and presentation logic
    • Each MVC object has different responsibilities
    • The development progresses in parallel
    • Easy to manage and maintain
    • All classes and object are independent of each other

    Disadvantages:

    • The model pattern is little complex
    • Inefficiency of data access in view
    • With modern user interface, it is difficult to use MVC
    • You need multiple programmers for parallel development
    • Multiple technologies knowledge is required

     

     

  16. Spring MVC Framework Tutorial

  17. Question 11. Explain The Role Of “actionfilters” In Mvc?

    Answer :

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

  18. Resource Description Framework (RDF) Interview Questions

  19. Question 12. Explain What Are The Steps For The Execution Of An Mvc Project?

    Answer :

    The steps for the execution of an MVC project includes
    •Receive first request for the application
    •Performs routing
    •Creates MVC request handler
    •Create Controller
    •Execute Controller
    •Invoke action
    •Execute Result

  20. . NET Interview Questions

  21. Question 13. Explain What Is Routing? What Are The Three Segments For Routing Is Important?

    Answer :

    Routing helps you to decide a URL structure and map the URL with the Controller.
    The three segments that are important for routing is
    •ControllerName
    •ActionMethodName
    •Parameter

  22. Question 14. Explain How Routing Is Done In Mvc Pattern?

    Answer :

    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 to 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.

  23. Question 15. Explain Using Hyperlink How You Can Navigate From One View To Other View?

    Answer :

    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”) %>

  24. Unittest Framework Interview Questions

  25. Question 16. Mention How Can Maintain Session In Mvc?

    Answer :

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

  26. Question 17. Mention What Is The Difference Between Temp Data, View, And View Bag?

    Answer :

    •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

  27. Spring MVC Framework Interview Questions

  28. Question 18. What Is Partial View In Mvc?

    Answer :

    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.

  29. Framework7 Interview Questions

  30. Question 19. Explain How You Can Implement Ajax In Mvc?

    Answer :

    In Ajax, MVC can be implemented in two ways
    •Ajax libraries
    •Jquery

  31. Question 20. Mention What Is The Difference Between “actionresult” And “viewresult”?

    Answer :

    “ActionResult” is an abstract class while “ViewResult” is derived from “AbstractResult” class.  “ActionResult” has a number of derived classes like “JsonResult”, “FileStreamResult” and “ViewResult” .
    “ActionResult” is best if you are deriving different types of view dynamically.

  32. Dot Net Framework Interview Questions

  33. Question 21. Explain How You Can Send The Result Back In Json Format In Mvc?

    Answer :

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

  34. Question 22. Explain What Is The Difference Between View And Partial View?

    Answer :

    View :

    • It contains the layout page
    • Before any view is rendered, viewstart page is rendered
    • View might have markup tags like body, html, head, title, meta etc.
    • View is not lightweight as compare to Partial View

    Partial View :

    • It does not contain the layout page
    • Partial view does not verify for a viewstart.cshtml. We cannot put common code for a partial view within the viewStart.cshtml.page
    • Partial view is designed specially to render within the view and just because of that it does not consist any mark up
    • We can pass a regular view to the RenderPartial method
  35. Question 23. List Out The Types Of Result In Mvc?

    Answer :

    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

  36. Net Micro Framework Interview Questions

  37. Question 24. Mention What Is The Importance Of Nonactionattribute?

    Answer :

    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.

  38. Java collections framework Interview Questions

  39. Question 25. Mention What Is The Use Of The Default Route {resource}.axd/{*pathinfo}?

    Answer :

    This default route prevents request for a web resource file such as Webresource.axd or ScriptResource.axd from being passed to the controller.

  40. Question 26. Mention The Order Of The Filters That Get Executed, If The Multiple Filters Are Implemented?

    Answer :

    The filter order would be like
    •Authorization filters
    •Action filters
    •Response filters
    •Exception filters

  41. Question 27. Mention What Filters Are Executed In The End?

    Answer :

    In the end “Exception Filters” are executed.

  42. Microsoft Solutions Framework (MSF) Interview Questions

  43. Question 28. Mention What Are The File Extensions For Razor Views?

    Answer :

    For razor views the file extensions are
    •.cshtml: If C# is the programming language
    •.vbhtml: If VB is the programming language

  44. Question 29. Mention What Are The Two Ways For Adding Constraints To A Route?

    Answer :

    Two methods for adding constraints to route is
    •Using regular expressions
    •Using an object that implements IRouteConstraint interface

  45. Question 30. Mention Two Instances Where Routing Is Not Implemented Or Required?

    Answer :

    Two instance where routing is not required are
    •When a physical file is found that matches the URL pattern
    •When routing is disabled for a URL pattern

  46. Question 31. Mention What Are Main Benefits Of Using Mvc?

    Answer :

    There are two key benefits of using MVC
    •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.

  47. Question 32. Name A Few Different Return Types Of A Controller Action Method?

    Answer :

    The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.
    1. ViewResult
    2. JavaScriptResult
    3. RedirectResult
    4. ContentResult
    5. JsonResult

     

  48. Question 33. Is Mvc Suitable For Both Windows And Web Application?

    Answer :

    MVC architecture is suited for web application than windows. For window application MVP i.e. “Model view presenter”is more applicable. If you are using WPF and SL MVVM is more suitable due to bindings.

  49. Resource Description Framework (RDF) Interview Questions

  50. Question 34. What Are The Benefits Of Using Mvc?

    Answer :

    There are two big benefits of MVC:-Separation of concerns is achieved as we are moving the code behind to a separate class file. By moving the bindingcode to a separate class file we can reuse the code to a great extent.Automated UI testing is possible because now the behind code (UI interaction code) has moved to a simple.NET class.This gives us opportunity to write unit tests and automate manual testing

  51. Question 35. How Can We Restrict Mvc Actions To Be Invoked Only By Get Or Post?

    Answer :

    We can decorate the MVC action by “HttpGet” or “HttpPost” attribute to restrict the type of HTTP calls. For instanceyou can see in the below code snippet the “DisplayCustomer” action can only be invoked by “HttpGet”. If we try tomake Http post on “DisplayCustomer” it will throw an error.
    [HttpGet]
    public ViewResult DisplayCustomer(int id)
    {
    Customer objCustomer = Customers[id];
    return View(“DisplayCustomer”,objCustomer);
    }

  52. Question 36. How Can We Maintain Session In Mvc?

    Answer :

    Sessions can be maintained in MVC by 3 ways tempdata ,viewdata and viewbag

  53. Unittest Framework Interview Questions

  54. Question 37. Can You Explain The Complete Flow Of Mvc?

    Answer :

    Below are the steps how control flows in MVC (Model, view and controller) architecture:-
    •All end user requests are first sent to the controller.
    •The controller depending on the request decides which model to load. The controller loads the model and attachesthe model with the appropriate view.
    •The final view is then attached with the model data and sent as a response to the end user on the browser

  55. Question 38. Where Is The Route Mapping Code Written?

    Answer :

    The route mapping code is written in the “global.asax” file.

  56. Question 39. Can We Map Multiple Url’s To The Same Action?

    Answer :

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

  57. Question 40. How Can We Navigate From One View To Other View Using Hyper-link?

    Answer :

    By using “ActionLink” method as shown in the below code. The below code will create a simple URL which help tonavigate to the “Home” controller and invoke the “GotoHome” action.
    <%= Html.ActionLink("Home","Gotohome") %>

  58. Spring MVC Framework Interview Questions