Covid-19 Update!!    We have enabled all courses through virtual classroom facility using Skype or Zoom.    Don't stop learning.    Enjoy Learning from Home.

30% Discount Python        30% Discount Webdesign        30% Discount SEO        30% Discount Angular8        Free SQL Class        Free Agile Workshop       Free HTML Sessions        Free Python Basics

Important MVC.NET Interview Questions and Answers

MVC.NET Interview Questions and Answers

1. Explain what is Model-View-Controller?

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

2. Mention what does Model-View-Controller represent in an MVC application?

In an MVC model,
Model– It represents the 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 answers to user actions and choose a view to provide the display to the user interface. The user input logic is contained with-in the controller

3. Explain in which assembly is the MVC framework is defined?

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

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

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

    5. 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 IRouteConstraint Interface
  • 6. Mention what “beforFilter()”,“beforeRender” and “afterFilter” functions do in Controller?

    beforeFilter(): It is run before every action and it’s the perfect place to check for an active session or view the user authority.
    beforeRender(): 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 final controller method to run.

    7. Explain the role of “ActionFilters” in MVC?

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

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

    MVC project includes the following steps:-
  • Receive first request for the application.
  • Performs routing .
  • Creates MVC request handler .
  • Create Controller.
  • Execute Controller .
  • Invoke action .
  • Execute Result.

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

    Which assists us to choose a URL structure and map the URL with the Controller is Routing.
    There are three segments that are major for routing is
  • ControllerName.
  • ActionMethodName.
  • Parameter.

    10. Explain how routing is done in MVC pattern?

    RouteCollection is a set of routes, which consists of filed 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 specification to the MapRoute method is the name of the route. The second specification 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.

    11. 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.
    Collapse / Copy Code
    <%= Html.ActionLink(“Home”, “Gotohome”) %>

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

    Temp data: It helps to keep 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

    13. What is partial view in MVC?

    Partial view renders a portion of view content. It is helpful in decrease code duplication or view within the parent view.

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

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

    15. Mention what is the importance of Non Action Attribute?

    All public technique of a controller class are used as the action method if you want to block this default method then you have to assign the public method with Non Action Attribute.

    16. Mention what is the use of the default route {resource}.axd/{*pathinfo} ?

    It stops the request for a web resource file like Webresource.axd or ScriptResource.axd from being proceed to the controller.

    17. Mention the order of the filters that get executed, if the multiple filters are implemented?

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

    18. Mention two instances where routing is not implemented or required?

    The instance where routing is not implemented are:-
  • When a physical file is found that equivalent the URL pattern.
  • When routing is disabled for a URL pattern.

    19. Mention what are the main benefits of using MVC?

    There are two key benefits of using MVC By using MVC, we have two advantages
  • As the code is passed behind a separate class file, you can use the code to a great range.
  • As behind code is simply moved to.NET class, it is practicable to automate UI testing.

    20. Mention what are the two ways for adding constraints to a route?

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