Most Asked ASP.NET MVC Questions and Answers Part-1

  1. What is MVC (Model View Controller)
MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller. Below is how each one of them handles the task.
  • The View is responsible for the look and feel.
  • Model represents the real world object and provides data to the View.
  • The Controller is responsible for taking the end user request and loading the appropriate Model and View
  1. 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.
 

  1. Explain in which assembly is the MVC framework is defined?
The MVC framework is defined in System.Web.Mvc.

  1. What are the advantages of MVC

  • A main advantage of MVC is separation of concern. Separation of concern means we divide the application Model, Control and View.
  • We can easily maintain our application because of separation of concern.
  • In the same time we can split many developers work at a time. It will not affects one developer work to another developer work.
  • It supports TTD (test-driven development). We can create an application with unit test. We can write won test case.
  • Latest version of MVC Support default responsive web site and mobile templates.
 


  1. 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.
  1. What is the difference between each version of MVC 2, 3 , 4, 5 and 6?

MVC 6 
ASP.NET MVC and Web API has been merged in to one.
Side by side - deploy the runtime and framework with your application
No need to recompile for every change. Just hit save and refresh the browser.
Dependency injection is inbuilt and part of MVC.
Everything packaged with NuGet, Including the .NET runtime itself.
New JSON based project structure.
Compilation done with the new Roslyn real-time compiler.

MVC 5
Asp.Net Identity
Attribute based routing
Bootstrap in the MVC template
Filter overrides
Authentication Filters

MVC 4
ASP.NET Web API
New mobile project template
Refreshed and modernized default project templates
Many new features to support mobile apps

MVC 3
Razor
HTML 5 enabled templates
JavaScript and Ajax
Support for Multiple View Engines
Model Validation Improvements

MVC 2
Templated Helpers
Client-Side Validation
Areas
Asynchronous Controllers
Html.ValidationSummary Helper Method
DefaultValueAttribute in Action-Method Parameters
Binding Binary Data with Model Binders
DataAnnotations Attributes
Model-Validator Providers
New RequireHttpsAttribute Action Filter


Post a Comment

0 Comments