Preparing for asp.net interview? If yes, here’s the most asked top 10 ASP.NET MVC interview questions.
Top 10 ASP.NET MVC Interview Questions
1. What is Model View Controller or MVC?
Model View Controller or MVC is a software architectural pattern for implementing user interfaces. It divides a given software application into three separate interconnected parts, so as to separate internal representation of information from the way that information is presented to or accepted from the user.
MVC is a framework for building web applications using a Model View Controller design:
- The Model represents the application core (for instance a list of database records).
- The View displays the data (the database records).
- The Controller handles the input (to the database records).
The MVC model defines web applications with 3 logic layers:
- The business layer (Model logic)
- The display layer (View logic)
- The input control (Controller logic)
The Model is the part of the application that handles the logic for the application data.
Often model objects retrieve data (and store data) from a database.
The View is the part of the application that handles the display of the data.
Most often the views are created from the model data.
The Controller is the part of the application that handles user interaction.
Typically controllers read data from a view, control user input, and send input data to the model.
The MVC separation helps you manage complex applications, because you can focus on one aspect a time. For example, you can focus on the view without depending on the business logic. It also makes it easier to test an application.
The MVC separation also simplifies group development. Different developers can work on the view, the controller logic, and the business logic in parallel.
2. What is the difference between ASP.NET MVC and ASP.NET Web Forms?
ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front controller approach. In case of Page controller approach, every page has its own controller i.e. code-behind file that processes the request. On the other hand, in ASP.NET MVC, a common controller for all pages processes the requests.
3. In which assembly is the MVC framework defined?
The MVC framework is defined in System.Web.Mvc.
4. What are the core features of MVC?
Benefits of MVC:
Multiple view support
Due to the separation of the model from the view, the user interface can display multiple views of the same data at the same time.
User interfaces tend to change more frequently than business rules (different colors, fonts, screen layouts, and levels of support for new devices such as cell phones or PDAs) because the model does not depend on the views, adding new types of views to the system generally does not affect the model. As a result, the scope of change is confined to the view.
SoC – Separation of Concerns
Separation of Concerns is one of the core advantages of ASP.NET MVC . The MVC framework provides a clean separation of the UI, Business Logic, Model or Data.
ASP.NET MVC framework provides better testability of the Web Application and good support for the test driven development too.
ASP.NET MVC framework doesn’t use View State and thus reduces the bandwidth of the requests to an extent.
Full features of ASP.NET
One of the key advantages of using ASP.NET MVC is that it is built on top of ASP.NET framework and hence most of the features of the ASP.NET like membership providers, roles, etc can still be used.
5. Can you please explain the request flow in ASP.NET MVC framework?
Request flow for ASP.NET MVC framework is as follows: Request hits the controller coming from client. Controller plays its role and decides which model to use in order to serve the request. Further passing that model to view which then transforms the model and generate an appropriate response that is rendered to client.
6. What is Routing in ASP.NET MVC?
In case of a typical ASP.NET application, incoming requests are mapped to physical files such as .aspx file. On the other hand, ASP.NET MVC framework uses friendly URLs that more easily describe user’s action but 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.
7. List out few different return types of a controller action method?
8. What is the difference between ViewData, ViewBag and TempData?
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 to communicate between controller and corresponding view. But this communication is only for server call, it becomes null if redirect occurs.
So, in short, its 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.
9. In which order filters gets executed, if the multiple filters are implemented?
The filter order would be like
- Authorization filters
- Action filters
- Response filters
- Exception filters
10. Mention two instances where routing is not implemented or required?
Two instance where routing is not required are
- When a physical file is found that matches the URL pattern
- When routing is disabled for a URL pattern
These are the most asked top 10 asp.net mvc interview questions. We do not sure you about what your interviewer will ask but we just sharing few of the questions asked very often.