+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

Top 20 Most Asked ASP .Net MVC Interview Questions and Answers

Sat, 2017-08-26 17:57
ASP .Net MVC Interview Questions

Are you preparing for ASP .Net MVC job interview and wondering what questions you might be asked? In this blog we have hand-picked the questions you are likely to be asked in ASP .Net MVC job interview and provided to-the-point answers to each one of them so as to help you prepare better for ASP .Net MVC job interviews.

Always keep in the mind that, only academic knowledge is not enough to crack an interview. Employers expects from the candidate to have practical knowledge and hands-on experience as well. This ASP .Net MVC Interview Questions designed by industry expert will help you to gain practical knowledge of ASP .Net MVC.

ASP .Net MVC Interview Questions and Answers

  1. What does MVC represent in ASP.NET?
  2. Answer:

    • MVC stands for Model-View-Controller pattern that represents an architectural pattern for software.
    • This separates the components of a Web application and helps in decoupling the business logic.
    • It gives more flexibility to overall architecture that allows the changes to be made to a
    • layer, without affecting the other.
    • M represents the Model view that specifies a specific domain data.
    • V represents the view of the user interface components used to display the Model data.
    • C represents the Controller that handles the user interactions and events. It manipulates the updates that model reflect at every change of the state of an application.
  1. Explain MVC (Model-View-Controller) in general?
  2. Answer:
    MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application.

    • "Model" is basically domain data.
    • "View" is user interface to render domain data.
    • "Controller" translates user actions into appropriate operations performed on model.
  1. What is difference between TempData and ViewData ?
  2. Answer:
    “TempData” maintains data for the complete request while “ViewData” maintains data only from Controller to the view.

  1. What is Repository Pattern in ASP.NET MVC?
  2. Answer:

    • Repository pattern is used as a default entity operation that allow the decoupling of the components used for presentation.
    • Repository pattern allows easy testing in the form of unit testing and mocking.
    • Repository pattern will have the proper infrastructure services to be used in the web applications.
    • It uses the mechanism of encapsulating that provides storage, retrieval and query for the implementation of the repository.
    • Repository patterns are hard coded in the application that is to be used in ASP.NET MVC architecture.
  1. What are Action Filters in ASP.NET MVC?
  2. Answer:
    If we need to apply some specific logic before or after action methods, we use action filters. We can apply these action filters to a controller or a specific controller action. Action filters are basically custom classes that provide a means for adding pre-action or post-action behavior to controller actions.
    For example:

    • Authorize filter can be used to restrict access to a specific user or a role.
    • OutputCache filter can cache the output of a controller action for a specific duration.
  1. What kind of logic view model class will have?
  2. Answer:
    As the name says view model this class has the gel code or connection code which connects the view and the model.
    So the view model class can have following kind of logics:-

    • Color transformation logic: - For example you have a “Grade” property in model and you would like your UI to display “red” color for high level grade, “yellow” color for low level grade and “green” color of ok grade.
    • Data format transformation logic :-Your model has a property “Status” with “Married” and “Unmarried” value. In the UI you would like to display it as a checkbox which is checked if “married” and unchecked if “unmarried”.
    • Aggregation logic: -You have two differentCustomer and Address model classes and you have view which displays both “Customer” and “Address” data on one go.
    • Structure downsizing: - You have “Customer” model with “customerCode” and “CustomerName” and you want to display just “CustomerName”. So you can create a wrapper around model and expose the necessary properties.
  1. What is the difference between ASP.NET MVC and ASP.NET WebForms?
  2. Answer:

    • NET WebForms uses the page controller patterns to render a layout. Whereas, ASP.NET MVC provides a model that doesn’t have connection with the View so it becomes easier to test and maintain the applications.
    • NET WebForms uses the Front controller pattern for all the pages to process the web applications requests and used to facilitate routing architecture. Whereas, ASP.NET MVC has the View that is called before the controller and this controller is used to render the View that is based on the actions as the user interacts with the interface.
    • NET WebForms manage the state of the model by using the view state and server based controls. Whereas, ASP.NET MVC doesn’t manage the state information like WebForms.
    • NET WebForms are event driven. Whereas, ASP.NET MVC are test driven.
  1. What is ASP.NET MVC?
  2. Answer:
    ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework.

  1. Does “TempData” preserve data in the next request also?
  2. Answer:
    “TempData” is available through out for the current request and in the subsequent request it’s available depending on whether “TempData” is read or not.
    So if “TempData” is once read it will not be available in the subsequent request.

  1. What are the namespace classes used in ASP.NET MVC?
  2. Answer:
    ASP.NET MVC uses the namespace classes that as follows:

    • Web.Mvc namespace: this consists of classes and interfaces that follows MVC pattern to create web applications. This includes the controllers, libraries, actions, views, models.
    • Web.Mvc.Ajax namespace: this consists of classes that support the AJAX scripts and used in the web applications. This also include the AJAX related settings and options.
    • Web.Mvc.Async namespace: this consists of classes and interfaces that provide asynchronous actions in the web applications.
    • Web.Mvc.Html namespace: this consists of classes in the form of helper application and follows the MVC pattern. This includes the forms, controls, links, views and validations
  1. Explain the role of Model in ASP.NET MVC?
  2. Answer:
    One of the core features of ASP.NET MVC is that it separates the input and UI logic from business logic. Role of Model in ASP.NET MVC is to contain all application logic including validation, business and data access logic except view, i.e., input and controller, i.e., UI logic.
    Model is normally responsible for accessing data from some persistent medium like database and manipulate it.

  1. How do we implement minification?
  2. Answer:
    When you implement bundling, minification is implemented by itself. In other words the steps to implement bundling and minification are the same.

  1. How is the ASP.NET MVC architecture different from others?
  2. Answer:

    • NET MVC uses a complete Model-View-Controller architecture that combines the Controller and the View in a way that both meet the dependency of each other.
    • The testing of the architecture can be done by instantiating a View and carrying out the unit tests without running the controllers through the complete cycle.
    • The control of MVC on the output is complete and it renders the HTML in a very clean way.
    • The architecture provides an orientation towards the standard compliant pages and control over the behavior of the applications.
    • The knowledge of many programming language gets reduced and the model can become more abstract from lots of details that is provided for the ease of use.
  1. What is Routing in ASP.NET MVC?
  2. Answer:
    In case of a typical ASP.NET application, incoming requests are mapped to physical files such as .aspx file. ASP.NET MVC framework uses friendly URLs that more easily describe user’s action but are not mapped to physical files.
    ASP.NET MVC framework uses a routing engine, that maps URLs to controller classes. We can define routing rules for the engine, so that it can map incoming request URLs to appropriate controller.
    Practically, when a user types a URL in a browser window for an ASP.NET MVC application and presses “go” button, routing engine uses routing rules that are defined in Global.asax file in order to parse the URL and find out the path of corresponding controller.

  1. So which is a better fit, Razor or ASPX?
  2. Answer:
    As per Microsoft, Razor is more preferred because it’s light weight and has simple syntaxes.

  1. What is the main function of Razor in ASP.NET
  2. Answer:

    • Razor is a view engine that allows the static HTML or the content to be started with the server and then the content is made dynamic by adding the server code to it.
    • Razor is designed to make the process of coding flexible and provide standardization.
    • Razor also provides an easy way to integrate the server code into the HTML markup with few keystrokes.
    • Razor is used a view engine that is very expressive in writing style. The coding becomes simpler due to the support libraries.
    • Razor supports many local functions with other functionalities that help in block reading and writing. It also has pre-defined set of functions that can be used to make the coding more easier.
  1. What is the difference between ViewData, ViewBag and TempData?
  2. Answer:

    • In order to pass data from controller to view and in next subsequent request, ASP.NET MVC framework provides different options i.e., ViewData, ViewBag and TempData.
    • Both ViewBag and ViewData are used to communicate between controller and corresponding view. But this communication is only for server call, it becomes null if redirect occurs. So, in short, it's a mechanism to maintain state between controller and corresponding view.
    • ViewData is a dictionary object while ViewBag is a dynamic property (a new C# 4.0 feature). ViewData being a dictionary object is accessible using strings as keys and also requires typecasting for complex types. On the other hand, ViewBag doesn't have typecasting and null checks.
    • TempData is also a dictionary object that stays for the time of an HTTP Request. So, Tempdata can be used to maintain data between redirects, i.e., from one controller to the other controller.
  1. What is WebAPI?
  2. Answer:
    HTTP is the most used protocol. For the past many years, browser was the most preferred client by which we consumed data exposed over HTTP. But as years passed by, client variety started spreading out. We had demand to consume data on HTTP from clients like mobile, JavaScript, Windows applications, etc.
    For satisfying the broad range of clients REST was the proposed approach. You can read more about REST from the WCF chapter.
    WebAPI is the technology by which you can expose data over HTTP following REST principles.

  1. Why it is useful to use MVC instead of WebForms?
  2. Answer:

    • MVC allows the user to write less amount of code to build the web applications as lots of components are integrated to provide the flexibility in the program.
    • Lot of data control options is being provided that can be used in ViewState.
    • The application tasks are separated into components to make it easier for the programmers to write the applications but at the same time the amount of the code also increases.
    • Main focus remains on the testability and maintainability of the projects that is being carried out in large projects.
    • It is being used for the projects that require rapid application development.
  1. How can you do authentication and authorization in MVC?
  2. Answer:
    You can use Windows or Forms authentication for MVC.

Hub4tech is a one of the few online training platforms who provide best in quality and cutting edge technology education directly from industry experts. Start your journey of becoming an ASP .Net MVC developer  with us. If you have any query regarding the data scientist or any of the blog information, please speak to our specialists here.

You can also send your query in our mail box at info@hub4tech.com, and we will write back or call back to you. Don’t forget to like our Facebook and LinkedIn page to get more technology updates. You can read all our Blogs here.

You can also check your level by participating in our free Online Assessment Tests

Use Full Link for ASP .Net MVC Training and Certification

Hitesh Patel
Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.