• Register
100 points

Want to solve programming problems and get paid for it? If that sounds interesting to you then contact us.

1. Explain what is Model-View-Controller?

MVC 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 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. 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 part of your project that makes project less development and maintenance cost
  • MVC makes your project more systematic

4.What is MVC Application Life Cycle ?

Any web application has two main execution steps first understanding the request and depending on the type of the request sending out the appropriate response. MVC application life cycle is not different it has two main phases first creating the request object and second sending our response to the browser. 

Creating the request object: -The request object creation has four major steps. Below is the detail explanation.

Step 1 Fill route:  MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the route table with routes collection. This filling of route table happens in the global.asax file. 

Step 2 Fetch route:  Depending on the URL sent “UrlRoutingModule” searches the route table to create “RouteData” object which has the details of which controller and action to invoke.

Step 3 Request context created: The “RouteData” object is used to create the “RequestContext” object.

Step 4 Controller instance created:  This request object is sent to “MvcHandler” instance to create the controller class instance. Once the controller class object is created it calls the “Execute” method of the controller class.

Step 5 Creating Response object:  This phase has two steps executing the action and finally sending the response as a result to the view.

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

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

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

There are total nine return types we can use to return results from controller to view.

  • ViewResult (View): This return type is used to return a webpage from an action method.

  • PartialviewResult (Partialview): This return type is used to send a part of a view which will be rendered in another view.

  • RedirectResult (Redirect): This return type is used to redirect to any other controller and action method depending on the URL.

  • RedirectToRouteResult (RedirectToAction, RedirectToRoute): This return type is used when we want to redirect to any other action method.

  • ContentResult (Content): This return type is used to return HTTP content type like text/plain as the result of the action.

  • jsonResult (json): This return type is used when we want to return a JSON message.

  • javascriptResult (javascript): This return type is used to return JavaScript code that will run in browser.

  • FileResult (File): This return type is used to send binary output in response.

  • EmptyResult: This return type is used to return nothing (void) in the result.

7.What are Filters in MVC?

In MVC, many times we would like to perform some action before or after a particular operation. For achieving this functionality, ASP.NET MVC provides feature to add pre and post action behaviors on controller's action methods.

Types of Filters: 

ASP.NET MVC framework supports the following action filters:

  • Action Filters: Action filters are used to implement logic that gets executed before and after a controller action executes.

  • Authorization Filters: Authorization filters are used to implement authentication and authorization for controller actions.

  • Result Filters: Result filters contain logic that is executed before and after a view result is executed. For example, you might want to modify a view result right before the view is rendered to the browser.

  • Exception Filters: You can use an exception filter to handle errors raised by either your controller actions or controller action results. You can also use exception filters to log errors.

8.What are HTML helpers in MVC?

HTML helpers help you to render HTML controls in the view. For instance if you want to display a HTML textbox on the view , below is the HTML helper code.

<%= Html.TextBox("FirstName") %>

For checkbox below is the HTML helper code. In this way we have HTML helper methods for every HTML control that exists.

<%= Html.CheckBox("Yes") %>


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

10.Mention what "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





100 points