A must have list of ASP.NET MVC Interview Questions and Answers with concepts and necessary code examples. If you understand following key concepts, you will definitely feel more comfortable during an interview. But along with that you need to prepare your practical skills on ASP.NET MVC technology.You can also find more related implementation details here:
- Take a FREE Online Test on ASP.NET MVC to verify you existing knowledge.
- The Complete ASP.NET MVC 5 Course
- Top New Features of ASP.NET vNext
- Building your first ASP.NET MVC 5 Application
- Understanding Model First Approach in MVC5 with EF6
- Understanding Application Life Cycle in ASP.NET MVC
- ASP.NET MVC3 Vs MVC4 Vs MVC5
- Pass Data from Controller to View (ViewBag | ViewData | TempData | Model)
- Using Bootstrap3 with ASP.NET MVC5
UPDATE: Although this tutorial targets top 10 most important and frequently asked interview questions but I have added few more questions at the end for readers to help them well prepare for ASP.NET MVC5 interview. Also, I have added Recent ASP.NET MVC Jobs at the end of this article that will definitely help you finding your dream job in IT Industry.
ASP.NET MVC Interview Questions List
- Explain MVC (Model-View-Controller) in general?
- What is ASP.NET MVC?
- Difference between ASP.NET MVC and ASP.NET WebForms?
- What are the Core features of ASP.NET MVC?
- Can you please explain the request flow in ASP.NET MVC framework?
- What is Routing in ASP.NET MVC?
- What is the difference between ViewData, ViewBag and TempData?
- What are Action Methods in ASP.NET MVC?
- Explain the role of Model in ASP.NET MVC?
- What are Action Filters in ASP.NET MVC?
More Interview Questions on ASP.NET MVC5
- What are the new features introduced in ASP.NET MVC5?
- What is a ViewEngine in ASP.NET MVC?
- What is the difference between Razor View Engine and ASPX View Engine?
- What is a ViewModel in ASP.NET MVC?
- What are ASP.NET MVC HtmlHelpers?
- What is Bootstrap in MVC5?
- Kindly explain Attribute Routing in ASP.NET MVC5?
- What is Scaffolding in ASP.NET MVC? and what are the advantages of using it?
- Briefly explain ASP.NET Identity?
- Is it possible in ASP.NET MVC Project to boost speed by caching the static content folder(s)?
ASP.NET CORE Interview Questions – ASP.NET CORE 1.0 – MVC6
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.
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. Back to top
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. Follow the link for the difference between the ASP.NET MVC and ASP.NET WebForms. Back to top
Core features of ASP.NET MVC framework are:
- Clear separation of application concerns (Presentation and Business Logic). It reduces complexity that makes it ideal for large scale applications where multiple teams are working.
- It’s an extensible as well as pluggable framework. We can plug components and further customize them easily.
- It provides extensive support for URL Routing that helps to make friendly URLs (means friendly for human as well as Search Engines).
- It supports for Test Driven Development (TDD) approach. In ASP.NET WebForms, testing support is dependent on Web Server but ASP.NET MVC makes it independent of Web Server, database or any other classes.
- Support for existing ASP.NET features like membership and roles, authentication and authorization, provider model and caching etc.
Follow for detailed understanding of above mentioned core features.
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. You can follow the link, in order to understand the Complete Application Life Cycle in ASP.NET MVC. Back to top
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.
Let’s see below URLs for both ASP.NET and ASP.NET MVC.
//ASP.NET approach - Pointing to physical files (Student.aspx)
//Displaying all students
//Displaying a student by Id = 5
//ASP.NET MVC approach - Pointing to Controller i.e. Student
//Displaying all students
//Displaying student by Id = 5
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. You can find complete details of ASP.NET MVC Routing here.
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. You can easily find detailed examples for implementation of ViewBag, ViewData and TempData here.
Back to top
Please choose the correct statements about ViewBag and ViewData [Choose Two]?
- A. ViewData is a Dictionary object and it requires typecasting while getting data.
- B. ViewData is a Dynamic Property so it doesn’t require typecasting for getting data.
- C. ViewBag is a Dictionary object and it requires typecasting while getting data.
- D. ViewBag is a Dynamic Property so it doesn’t require typecasting for getting data.
Correct Answer: A, D
If you want to further test your ASP.NET MVC skill, Take a Complete FREE Online Test or MCSD Practice Exam: 70-486 (Developing ASP.NET MVC Web Applications). Simply Click Here.
As I already explained about request flow in ASP.NET MVC framework that request coming from client hits controller first. Actually MVC application determines the corresponding controller by using routing rules defined in Global.asax. And controllers have specific methods for each user actions. Each request coming to controller is for a specific Action Method. The following code sample, “ShowBook” is an example of an Action Method.
public ViewResult ShowBook(int id)
var computerBook = db.Books.Where(p => P.BookID == id).First();
Action methods perform certain operation using Model and return result back to View. As in above example, ShowBook is an action method that takes an Id as input, fetch specific book data and returns back to View as ViewResult. In ASP.NET MVC, we have many built-in ActionResults type:
- and many more….
For a complete list of available ActionResults types with Helper methods, please click here. Important Note: All public methods of a Controller in ASP.NET MVC framework are considered to be Action Methods by default. If we want our controller to have a Non Action Method, we need to explicitly mark it with NonAction attribute as follows:
public void MyNonActionMethod()
One of the core feature 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, so you can expect that interviewer can ask questions on database access topics here along with ASP.NET MVC Interview Questions. Back to top
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 mean 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.
- and more…
- Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
- AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level The Fastest Way For .NET Developers To Add AngularJS To Their Resume
- ASP.NET with Entity Framework from Scratch [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level Latest approach of web application development
- Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels From zero knowledge of ASP.NET to deploying a complete project to production.
More Interview Questions on ASP.NET MVC5
“View Engine in ASP.NET MVC is used to translate our views to HTML and then render to browser.” There are few View Engines available for ASP.NET MVC but commonly used View Engines are Razor, Web Forms/ASPX, NHaml and Spark etc. Most of the developers are familiar with Web Forms View Engine (ASPX) and Razor View Engine.
- Web Form View Engine was with ASP.NET MVC since beginning.
- Razor View Engine was introduced later in MVC3.
- NHaml is an open source view engine since 2007.
- Spark is also an open source since 2008.
I have written a separate detailed blog post to understand the Difference between ASPX View Engine and Razor View Engine. You can follow the link to get detailed step by step description here. Most important differences are listed below:
ASPX View Engine
Razor View Engine
|WebForms View Engine uses namespace “System.Web.Mvc.WebFormViewEngine”.||“System.Web.Razor” is the namespace for Razor View Engine.|
|Comparatively fast.||A little bit slower than ASPX View Engine.|
|Nothing like Test Driven Development||Good support for Test Driven Development.|
|Syntax for ASPX View Engine is inherited from Web Forms pages as: <%= employee.FullName %>||Syntax for Razor View Engine is comparatively less and clean. @employee.FullName|
Yes, it’s possible. As we know that by default two view engines are installed.
- WebForm ViewEngine
- Razor ViewEngine
If we are 100% sure that we are only going to use say ‘Razor ViewEngine’, and WebForm ViewEngine will remain idle/unused all the time, then we can remove the unused View engine by following the below simple steps:
- In our Gloabal.asax file, clear all the ViewEngines on Application_Start method.
- Add the specific one i.e Razor ViewEngine to our ViewEngine collection.
A ViewModel basically acts as a single model object for multiple domain models, facilitating to have only one optimized object for View to render. Below diagram clearly express the idea of ViewModel in ASP.NET MVC: There are multiple scenarios where using ViewModel becomes obvious choice. For example:
- Parent-Child View Scenario
- Reports where often aggregated data required
- Model object having lookup data
- Dashboards displaying data from multiple sources
ASP.NET MVC HtmlHelpers fulfills almost the same purpose as that of ASP.NET Web From Controls. For imlementation point of view, HtmlHelper basically is a method that returns a string ( i.e. an HTML string to render HTML tags). So, in ASP.NET MVC we have HtmlHelpers for links, Images and for Html form elements etc. as follows:
@Html.ActionLink(“WebDev Consulting Company Profile”, “CompanyInfo”)
<a href="”/Site/CompanyInfo”">WebDev Consulting Company Profile</a>
<input id="”strEmployeeName”" name="”strEmployeeName”" type="”text”" value="””" />
For a complete reference to Standard ASP.NET MVC Html Helpers, Click Here.
Note: Html Helpers are comparatively lightweight because these don’t have ViewState and event model as for ASP.NET Web Form Controls.
Note: You can follow here to learn step by step how we can use any theme in Bootstraps to our ASP.NET MVC web application. If you are further interested to learn Bootstrap in much detailed level, a very comprehensive course is available that teaches you bootstrap by building 10 professional projects.
We already have discussed about Routing in Question#6 that in ASP.NET MVC, we use friendly URLs that are mapped to controller’s actions instead of physical files as in case of ASP.NET WebForms. Now in ASP.NET MVC5, we can use attributes to define routes giving better control over the URIs. We can easily define routes with Controller’s action methods as follows:
Note: Remember that conventional routing approach is not discarded, it’s still there and fully functional. Also, we can use both routing techniques in a same application. Click here for more details on Attribute Routing.
We (developers) spent most of our time writing code for CRUD operations that is connecting to a database and performing operations like Create, Retrieve, Update and Delete. Microsoft introduces a very powerful feature called Scaffolding that does the job of writing CRUD operations code for us.
- RAD approach for data-driven web applications.
- Minimal effort to improve the Views.
- Data Validation based on database schema.
- Easily created filters for foreign key or boolean fields.
- A. We can’t make a public method as non action in ASP.NET MVC.
- B. Make return type void to a public method.
- C. Add NonActionAttribute attribute to a public method.
- D. Add VoidAttribute attribute to a public method.
Want to improve you ASP.NET MVC skill, Take a Complete FREE Online ASP.NET MVC Test or MCSD Practice Exam: 70-486 (Developing ASP.NET MVC Web Applications). Simply Click Here.
Correct Answer: C
Microsoft introduces ASP.NET Identity as a system to manage access in ASP.NET application on premises and also in the cloud. There were issues with Membership Provider Model especially when we want to implement more advanced security features in our applications, so ASP.NET Identity gets away from the membership provider model. If we look into the history of membership, its like follows:
- ASP.NET 2.0 Membership (VS 2005)
- Forms Authentication
- Sql Server Based Membership
- ASP.NET Simple Membership (VS 2010)
- Easy to customize profile
- ASP.NET Web Pages
- ASP.NET Universal Providers (VS2012)
- Support Sql Azure
Yes, we can easily boost speed for static content folder(s) by applying caching on specific content folder. It’s a simple 2 step process as follows:
- Place the web.config inside the content folder, and
- Set the cacheControlMaxAge property to specific value you want.
It’s an older approach, we have been using since long with apply folder specific settings.
Complete code for applying caching to boost speed for static content folders as follows:
<?xml version="1.0" encoding="UTF-8"?>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="3.00:00:00" />
This will inform the client to cache the static content for 3 days in that folder as well as the subfolders under it.
ASP.NET CORE Interview Questions – ASP.NET Core 1.0 – MVC6
ASP.NET Core 1.0 also known as ASP.NET 5 – MVC6 is a re-write version of ASP.NET 4.6 with following key features:
- ASP.NET Core is Open-Source.
- ASP.NET Core is Cross-Platform framework means can run on Linux or MacOS – a huge enhancement.
- Ideal for building web applications, Iot apps and mobile backends.
- Cloud ready configuration.
- ASP.NET Core 1.0 is smaller in size as compared to ASP.NET 4.6 framework as it runs on stripped down version of .NET Framework i.e. .NET Core 1.0
At a broader view, ASP.NET 5 is now renamed as ASP.NET Core 1.0; .NET Framework 5 will be known as .NET Core 1.0 and Entity Framework 7 will be renamed to Entity Framework Core 1.0.
Back to top
ASP.NET MVC is an amazing framework for developing applications. Above mentioned ASP.NET MVC interview questions must be prepared before appearing for a MVC interview.
Junior .NET Developer
|Port Washington, NY 11050||12-April-2017|
Senior .Net Developer
|San Luis Obispo, CA||21-April-2017|
.NET Software Engineer
Junior .Net Developer
Senior .Net Developer (Full-Stack)
|Harrisburg, PA 17112||13-April-2017|
Senior.Net Web Developer
Senior .NET Developer
Junior to Mid-level .Net Developer
|Baton Rouge, LA||23-March-2017|
|San Diego, CA 92122||26-April-2017|
Junior .NET Web Developer
|Atlanta North, GA||11-April-2017|
Senior Software Developer .NET ASP.NET MVC
|New York, NY 10006||31-March-2017|
Sr. C#/ASP.NET Developer
|Seattle, WA 98115||18-April-2017|
.NET Software Engineer
Software Development Engineer (.NET)
Full stack .Net Mobile Application Developer
|Sacramento, CA 95834||25-April-2017|
Senior C#/.NET Full Stack Developer
|Beaverton, OR 97008||09-March-2017|
Junior .NET Developer (no 3rd party candidates)
|Annapolis, MD 21401||21-April-2017|
More You Must Read about ASP.NET MVC & Related
- ASP.NET MVC3 Vs MVC4 Vs MVC5 Vs MVC6
- 4 Simple Steps to Create your First ASP.NET MVC5 Application
- Understanding ASP.NET MVC Application Life Cycle
- How Routing works in ASP.NET MVC?
- All you need to Know about Controllers and Action Methods in ASP.NET MVC
- Practical Example to learn Scaffolding in ASP.NET MVC
- How to use AJAX in ASP.NET MVC Application?
- Insight of ASP.NET MVC Authorize attribute
- Building ASP.NET MVC5 Application with Entity Framework 6
- Understanding Model-First Approach in ASP.NET MVC with Entity Framework
- ASP.NET View Engine Vs Razor View Engine
- ViewBag Vs ViewData Vs TempData Vs Session
- How to use Model to Pass data to View in ASP.NET MVC?
- Understanding Partial View in ASP.NET MVC
- ASP.NET MVC Helpers – A MUST KNOW
- 2 simple ways to create Custom HTML Helpers in ASP.NET MVC
- All you need to know to pass Exam: 70-486 (Developing ASP.NET MVC Web Applications)
- Free Practical Guide to ASP.NET Web API
- Difference between WCF and ASMX web service
- WCF Hosting (Console | Windows Service)
Top 10 Interview Questions and Answers Series:
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions
- a Must Have SharePoint Interview Questions