Sunday 29 January 2017

MVC interview questions Part 1

Ques: Explain MVC architecture?
Answer: 
The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components

Model: Model is a set of classes that describe the business logic for the application data.
View  : View is UI components which  display of the data on browser.
Controller : Controllers responsible to process incoming requests.it manuplate logic with modal and bind data modal with view.


Ques: Explain ASP.NET MVC Pipeline Request Life Cycle?
                         or
          Explain Request Life Cycle of ASP.NET MVC ?
Answer:
Here the diagram show the sequence of Request Life Cycle of ASP.NET MVC.


Request come from IIS enter into url routing module. The routing table find out which
controler action method map to incoming URL pattern. Now in Routing module  there is MVC routeHandler which bring the request to MVC HttpHandler. Now MVC HttpHandler start intilizing of Controler and excute it. The MVCHttpHandler has IControllerFactory factory which responsible for excute instnce of controler. Once the controller has been instantiated, Controller's ActionInvoker determines which specific action to invoke on the controller.once Action method has been finished executing the next step is Result execution.If the result is a view type, the View Engine will be called and it's responsible for finding and rending our view.


Ques:  What are advantages of ASP.NET MVC framework ? 
Answer:
The following lists are the asp.net page life-cycle events.

 Separation of Concerns :It is core advantages MVC framework.The framework divides into three main part Model, View and Controller which make it easier to manage the application complexity.

 Lightweight framework: ASP.NET MVC framework doesn’t View State and thus reduces the bandwidth of the requests to an extent.

Test-driven development : The MVC framework brings better support to test-driven development.Unit Test can done very esaly.

Easy Extensible and pluggable: ASP.NET MVC framework easly customized with diffrent pluggin & Extensible after development over.

Search Engine Optimization (SEO) Friendly : URL's are more friendly for search engines because of URL routing mechanism.

ASP.NET features are supported:  MVC is built on top of ASP.NET so all of the features that ASP.NET include in this framework.

Less change Requirement Time : Developer can do change Requirement very frequently in very less time.

Ques: List out few different return types of a controller action method ?
Answer: 
View Result
Javascript Result
EmptyResult
PartialViewResult
JavaScriptResult
RedirectToRouteResult
Redirect Result
Json Result
Content Result
FileContentResult
FileStreamResult
FilePathResult


Ques: What are the difference between ViewData, ViewBag, Temp data and Session?
Answer: 

ViewData-
  • ViewData is used to pass data from controller to view.
  • It is available for the current request only.
  • ViewData is a dictionary which is derived from ViewDataDictionary class.
  • ViewData requires typecasting for complex data type and check null values to avoid error.
  • If redirection occurs, then its value becomes null.
  • It maintain data when request move from controller to view.
  • ViewData is Faster than ViewBag
  • ViewData is introduced in MVC 1.0
ViewBag-
  • ViewBag is also used to pass data from controller to view.
  • ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0
  • It is also available for the current request only.
  • If redirection occurs, then its value becomes null.
  • ViewBag doesn’t require typecasting for complex data type.
  • ViewBag is slower than ViewData.
  • ViewBag is introduced in MVC 3.0
TempData-
  • TempData is a dictionary object and it is property of controllerBase class.
  • TempData is used to pass data from one controler to another controler.
  • TempData is only work during the current and subsequent request.
  • TempData is derived from TempDataDictionary class.
  • It requires typecasting for complex data type and checks for null values to avoid error. 
  • It helps to maintain the data when we move from one controller to another controller or from one action to another action
  • TempData introduced in MVC1.0 
Session -
  • Session data mentain for all request until session timeout not expired.
  • Session is valid for all requests, not for a single redirect.
  • It requires typecasting for type and checks for null values to avoid error.
  • Session data are stored in SessionStateItemCollection object.



No comments:

Post a Comment

Thank you for comment