ASP.NET MVC Interview Questions
ASP.NET MVC interview questionsThese ASP.NET MVC questions have been designed for various interviews, competitive exams and entrance tests. We have covered questions on both basic and advanced concepts which will help you improve your skills to face interview questions on ASP.NET MVC.
Who is this ASP.NET MVC interview questions designed for?All the Web developers, Front End developers, UI/ UX developers and designers will find these questions extremely useful. All freshers, BCA, BE, BTech, MCA and college students wanting to make a career in front end designing will be highly benefitted by these questions.
ASP.NET MVC interview questions topicsThis section covers ASP.NET MVC topics like - ASP.NET MVC Life Cycle, Routing, Controllers, Actions, Filters, Selectors, Views, Data Model, Helpers, Model Binding, Databases, Validation, Security, Caching, Razor, Data Annotations, Web API, Scaffolding etc.
1. What is MVC?Answer:
MVC stands for Model, View, and Controller. MVC is a software architectural pattern which separates the representation and user interaction.
Model represents the real world object and provides data to the view. It is nothing but a set of classes that describes business logic.
View is responsible for look and feel. It represents UI components like HTML, CSS, jQuery etc.
Controller is responsible for taking the end user request via View and loading the appropriate Model and View.
2. How Model, View, Controller communicate each other in ASP.Net MVC?Answer:
User interacts with the controller.
There is one-to-many relationship between Controller and View which means one controller can mapped to multiple views.
Controller and View can have a reference to model.
Controller and View can talk to each other.
Model and View cannot talk to each other directly. They communicate to each other with the help of controller.
3. What are the advantages of ASP.Net MVC over ASP.Net web form?Answer:
There are following advantages of using ASP.NET MVC over ASP.NET web form.
i. The MVC framework provides a clean separation of the UI, Business Logic, Data or model.
ii. Automated UI testing is possible because now the behind code (UI interaction code) has moved to a simple .NET class. This gives us opportunity to write unit tests and automate manual testing.
iv. The ASP.NET MVC is lightweight because it doesn’t use viewstate and thus reduces the bandwidth of the request.
v. The ASP.NET MVC is supported most of the feature of ASP.NET web form like authentication and authorization, roles, caching, session etc.
4. Explain the difference between 3-layer architecture and MVC architecture.Answer:
MVC is an evolution of a three layered traditional architecture. Many components of the three layered architecture are the part of MVC.
A fundamental rule in three tier architecture is the client tier never communicate directly with the data tier. In a three-tier model all communication must pass through the middle tier.
MVC architecture is triangular. The view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model.
5. Explain the MVC application life cycle.Answer:
Any web application first understands the request and depending on type of request, it sends out 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.
The request object creation has four major steps,
Step 1: Fill route
Every MVC request is mapped to route table which specifies which controller and action to be invoked. If it is the first request, it fills the route table with route 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. RouteData 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
The coming request object is sent to "MvcHandler" instance to create the object of controller class. Once the controller class object is created, it calls the "Execute" method of the controller class.
Creating Response object:
This phase has two steps - Executing the action and finally sending the response as a result to the view.
6. What are the different return types of controller action methods?Answer:
There are total nine return types to return results from controller to view. The base type of all these result types is ActionResult.
1. ViewResult (View): It is used to return a webpage from an action method.
2. PartialviewResult (Partialview): It is used to send a part of a view which will be rendered in another view.
3. RedirectResult (Redirect): This return type is used to Redirects to another action method by using its URL.
4. RedirectToRouteResult (RedirectToAction, RedirectToRoute): It is used to Redirects to another action method.
5. ContentResult (Content): It returns a user defined content type.
6. JsonResult (Json): This return type is used to return a serialized JSON object.
8. FileResult(File): This return type is used to returns binary output to write to the response.
9. EmptyResult(): This return type is used to represent a return value that is used if the action method must return a null result (void).