Books of .Net/Interview Questions Interview Questions and Answers Programs C# Concept OOPS Concept JOBS

Sunday, July 16, 2017

ASP.NET MVC Interview Questions and Answers 1

Question 1: List out different return types of a controller action method?
Answer: There are total nine return types we can use to return results from controller to view. 

The base type of all these result types is ActionResult.

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

Question 2: What are Filters in MVC?
Answer: In MVC, controllers define action methods and these action methods generally have a one-to-one relationship with UI controls such as clicking a button or a link, etc. 
But 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.
ASP.NET MVC Filter is a custom class where you can write custom logic to execute before or after an action method executes. Filters can be applied to an action method or controller in a declarative or programmatic way. Declarative means by applying a filter attribute to an action method or controller class and programmatic means by implementing a corresponding interface.
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: Exception filters are the last type of filter to run. 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.
Action filters are one of most commonly used filters to perform additional data processing, or manipulating the return values or cancelling the execution of action or modifying the view structure at run time.



Question 3: Mention what is the difference between Temp data, View, and View Bag?
Answer: In ASP.NET MVC there are three ways to pass/store data between the controllers and views.

ViewData
ViewData is used to pass data from controller to view.
It is derived from ViewDataDictionary class.
It is available for the current request only.
Requires typecasting for complex data type and checks for null values to avoid error.
If redirection occurs, then its value becomes null.

ViewBag
ViewBag is also used to pass data from the controller to the respective 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.
Doesn’t require typecasting for complex data type.

TempData
TempData is derived from TempDataDictionary class
TempData is used to pass data from the current request to the next request
It keeps the information for the time of an HTTP Request. This means only from one page to another. It helps to maintain the data when we move from one controller to another controller or from one action to another action
It requires typecasting for complex data type and checks for null values to avoid error. Generally, it is used to store only one time messages like the error messages and validation messages


Question 4: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.

Question 5: What is Bundling and Minification in MVC?
Answer: Bundling and minification are two new techniques introduced to improve request load time. It improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript).

Bundling: It lets us combine multiple JavaScript (.js) files or multiple cascading style sheet (.css) files so that they can be downloaded as a unit, rather than making individual HTTP requests.
in other words,Bundling is a process of grouping the css / javascript files.This group of multiple file is combined into a single file.
This single file can be cached.Intention of bundling is to improve performance / optimization.

Minification: It squeezes out whitespace and performs other types of compression to make the downloaded files as small as possible. At runtime, the process identifies the user agent, for example IE, Mozilla, etc. and then removes whatever is specific to Mozilla when the request comes from IE.

Main intention of minification is to decrease the size of javascript / css files so that load time will get decreased.

Functionality of javacript / css file remains same in minification.



You may also like




1)Abstraction and Encapsulation in OOPS

2)Inheritance in OOPS

3)Polymorphism in OOPS

4)Interface in OOPS

5)What is Virtual Function

6)What is Abstract class and Abstract function

7)What is Static Class and Static Members

8)What is Collections

9) What is Generics

10)What is Delegate

11)Exception Handling

12)Static Constructor




1)How to make a Registration Page using CAPTCHA in C#

2)How to make a Login Window in C# - Step by Step

3)How to make PhoneBook in C#

4)Insert,Update ,Delete in a C#

2)C# Interview Questions and Answers Part 2

3)C# Interview Questions and Answers Part 3

4)C# Interview Questions and Answers Part 4    


1 comment :

  1. https://asptemplatestack.com/
    This web application provides you option to choose between templates with different pre-set features by your choise and download it in less than a minute. Moreover each of the most important features of the templates are well explained and documented.
    If you like what we are doing you can follow us in our linkedin page to stay informed about our new inprovements.

    ReplyDelete