Top 28 ASP.NET MVC 5 Interview Questions and Answers

MVC5 QnA Contents :-

What is MVC? 

MVC Stands for MODEL-VIEW-CONTROLLER is a Software Architectural Pattern.Which has been implemented across multiple development platforms and languages.It is divided into three components Model, View and Controller

Explain Model, View and Controller in MVC? 

View used to display the User interface and basically a HTML template.Model contains real world objects, data and business logic.Controller handles user interaction and loads the appropriate models and views.

Which assembly defines MVC framework? 

The MVC framework is defined in System.Web.Mvc.

What is the latest version of MVC in .Net development? 

MVC 5 is the latest version of MVC architectural pattern as of 2017 which runs on .Net 4.7 framework

What are the different types of Session management in MVC? 

The different ways of managing Session in MVC are TempData, ViewData and ViewBag.

Explain the difference between TempData, ViewData and ViewBag? 

TempData is used to move data from one controller to another or from one action to another also it internally uses ViewData.ViewData is used to transfer data from Controller to View.ViewBag is used to transfer data without casting as it uses dynamic keyword and Internally implements ViewData.

Explain Partial Views in MVC? 

Partial Views is a reusable chunk html code that can be inserted into existing View.They are used to display dynamic content in View with Static layout page.It does not contain a layout page and hence doesn't consist of mark up.

Explain Validation in MVC? 

Three things are needed to handle validation in MVC :
Data annotations which are nothing but attributes which can used on model Properties.
ValidateMessageFor which is an html helper class must be used to display the error ModelState.IsValid must be used in controller to take action according to user Response.

What is Razor View in MVC? 

Razor is a lightweight View engine introduced in MVC3.
Razor Views can be created with two extensions: .cshtml for C#
.vbhtml for Visual Basic.

What are the Advantages of MVC? 

Applications developed are lightweight also it suited to develop applications that are complex.
Separation of Concerns allows for compartmentalization of Presentation (UI)Business which allows high productivity and development time with large teams.
MVC applications have extensible URL Support making it easy to use option for the End user. MVC testing is independent of Web Server, database or any other classes due to it supporting Test Driven Development (TDD) approach. Concept of View State is eliminated which allows the building of a light weight Application while giving full controller to the developer. MVC patterns has been in use for many years in different web development Platforms as it popular method of development in larger projects hence far more Efficient than Code Behind development in Web Forms.

What are Filters in MVC? 

Filters are used to add logic code that will execute before or after a controller executes an Action method.
Types of Filters:
Action Filters
Authorization Filters
Result Filters
Exception Filters

Difference between Web Forms vs. MVC? 

MVC uses Front Controller approach which means there is a common controller for all pages instead of every page having its own controller like in Web Forms which uses code-behind file that will process the request.
MVC architecture has a very clean separation of concern between Controllers, Models and Views unlike Web Forms.
MVC application apply a approach which is stateless as per common HTTP convention different from Web Forms which use View State.
Development of a MVC application requires a better and detailed knowledge of JavaScript, HTML and CSS.
Absence of Life Cycle in MVC leads to a simpler request cycle which reduces load times MVC does not follow the RAD (Rapid Application Development) approach which may slow down development for people but it is better for Custom Application as developer has more Control over the code.
MVC is a recommended approach for Larger Application development where multiple teams are working in conjunction.

Explain Html Helpers in MVC? 

Html Helpers in MVC work in almost the same way as Server Control as they are used to generate Html elements which might be needed for links, Images and for form Elements.These Html Helpers are light weight as they do not contain View State and event model attached to them.

What are Action Filters in MVC? 

The action filter is an attribute that we can apply on a controller action or an entire controller if we need to.
Types of Action Filter:

  • OutputCache -It is used cache the output of a controller action for a specified period of time.
  • HandleError - It is used to handle errors raised when a controller action executes in MVC.
  • Authorize - It enables you to restrict access to a particular user or role.

What are Action Methods in MVC? 

Action Methods in MVC are required to execute requests and generate responses to the respective request which they generate in the form of Action Result.
Action Methods must always be public and they cannot be overloaded.
Action methods can never be Static.

What is a ViewModel in MVC? 

In Simple words we can display data from Multiple Models in a Single View via View Model.
View Models are generally used only to render views.
It is used to maintain separation of concern.

What is a View Engine in MVC? 

View Engine is used to render our view into html so that it can be properly displayed in our browser
MVC uses Razor View Engine for which we must use the namespace Web.Razor.

What are the different types of Action Filters in MVC? 

Authorization filters, Action filters, Result filters and Exception filters are the different types of Action Filters in MVC.

What is Bundling and Minification in MVC? 

Bundling and Minification are used to decrease the file size of CSS and JavaScript files and decrease load times thus increasing performance.
Bundling refers to combining multiple CSS and JavaScript files into a single one to avoid multiple request to load different files.
Minification refers to removing white spaces in CSS and JavaScript files to decrease it size and increase performance.

Explain Scaffolding in MVC? 

Scaffolding in MVC is used to auto-generate CRUD code in MVC template.
Where CRUD stands for Create, Read, Update and Delete.

Explain Exception handling in MVC? 

Exception handling is necessary to track errors in our application and display proper message on their occurrence
Exception handling in MVC can be done by the following way:

  • Simple try and catch
  • Override “On Exception” method
  • Using “Handle Error” Attribute
  • Inheriting from “HandleErrorAttribute”
  • Handling HTTP errors
  • Global Error handling in MVC

Explain Areas in MVC? 

The Concept of Area is to divide a large application in multiple smaller modules so that they are easy to develop and maintain in the future.
Each Area have their own controllers, models, and views.
Each Functionality Unit is in a different model.

Explain Layout View in MVC? 

In an application navigating from one page to another some parts of the UI remain the same to avoid creating the same UI on multiple pages and to only change the dynamic code we use layout page.
Layout page is similar to Master page in ASP Web Forms.

What is WebAPI? 

API stands for Application Program Interface.
Web API's are widely used to send and receive http request.
WebAPI can be said to a contract provided by one piece of software to another,they are used implementing a system of structured request and response.

What is Restful WebAPI? 

Rest stands for Representational State Transfer.
Rest is an Architectural style for designing networked applications.
It relies on Stateless, Client-Server protocol and almost it's always HTTP.
Rest treats server objects as resources that can created or destroyed.
It can be used in virtually any language.
Hence the API that follows this structure is called Restful WebAPI.

What is Output Caching in MVC? 

Output Caching is used to greatly improve the performance of a MVC application.
It allows us to cache the content returned a controller so that the same content does not need to be regenerated each time the same controller method is invoked upon request.
It reduces network traffic, reduces server round trips, reduces database round trips etc.
But few things should be kept in mind while using this i.e. we must avoid caching content that are unique per user along with using Caching for content that is accessed frequently and avoiding caching of contents that are rarely used.

Explain attribute based routing in MVC? 

This is a new Feature Introduced in MVC 5
By using Route Attribute on top of ActionResult we can define a custom route to navigate to that particular view in our browser.

What is ASP.Net Core2.0 MVC? 

  • It is the biggest redesign of the ASP.Net since ASP.Net 1.0
  • ASP.Net Core is no longer based on System.Web.dll
  • The ASP.Net Core application can run on either .Net Core or the Full .Net Framework.
  • ASP.Net Core applications can be hosted on Windows, Linux and MacOS.
  • It is Open source and Community supported.
  • This Applications can be hosted on IIS or can be hosted on nginx or other non-windows servers on top of Kestrel Web Server.
  • A new structure of MVC is applied in MVC Core 2.0
  • This includes Elimination of few files and incorporating the code into Startup class
  • While still retaining its Model, Controller and View components structure.

Explain Major changes in MVC Core 2.0? 

Comparing the Project structure of MVC 5 and MVC Core 2.0 we can clearly see the absences of Global.asax and Web.Config

There is no Content, Script and Font folders as all these contain Static files which are now housed under a single folder in MVC Core 2.0 called wwwroot.

appsettings.json and configuration files which can be customized to any format such as XML, Json etc.

In ASP.Net Core 2.0 router configuration does not have a separate file like in MVC 5 it's incorporated in Startup.cs itself.

Dependency Injection is Inbuilt in ASP.Net Core Applications so we can just create a service and use it with dependency injection unlike in MVC 5 in which we have to separate DI containers.

In ASP.Net Core 2.0 MVC we have IActionResult instead of ActionResult as return type in controller.

Author: Gurunatha Dogi

Gurunatha Dogi

Gurunatha Dogi is a software engineer by profession and founder of, Onlinebuff is a tech blog which covers topics on .NET Fundamentals, Csharp, Asp.Net, PHP, MYSQL, SQL Server and lots more..... read more

Add a Comment