We are going to share with you the top 10 interview questions and answers in ASP.NET/MVC for your preparation purpose:
1- What is MVC
Model–view–controller (MVC) is a software design pattern for implementing user interfaces on computers. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted by the user.
As an ASP.NET MVC is a framework for building web applications using an MVC (Model View Controller) design pattern:
- A Model: represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.
- A View: is a collection of classes representing the elements in the user interface (all of the things the user can see and respond to on the screen, such as buttons, display boxes, and so forth)
For more information about how to build an MCV application visit this website
2- What are routs in MVC and where to configure them?
Routing is a way to process the incoming URL that is more descriptive and gives the desired response. A route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as a .aspx file in a Web Forms application. A handler can also be a class that processes the request, such as a controller in an MVC application. To define a route, you create an instance of the Route class by specifying the URL pattern, the handler, and optionally a name for the route.
3- What Are Action Filters in MVC?
Action Filters: Action filters are used to implement logic that gets executed before and after a controller action executes.
4- What is Razor Engine and how it works?
Razor is an ASP MVC view engine that lets you to write server-based code in your view to create dynamic content the render it into valid HTML
5- Mention three ways to pass data between the controllers and views, and when to use each of them.
ViewData: It is available for the current request only and requires typecasting for complex data types.
ViewBag: Dynamic property that takes advantage of the new dynamic features in C# 4.0, also available for the current request only. If redirection occurs, then its value becomes null and doesn’t require typecasting for the complex data type.
TempData: used to pass data from the current request to the next request, keeps the information for the time of an HTTP Request. This means only from one page to another.
6- What are HTML Helpers and why use them?
HtmlHelper class generates HTML elements using the model class object in razor view. It binds the model object to HTML elements to display the value of model properties into HTML elements and also assigns the value of the HTML elements to the model properties while submitting the web form. So always use HtmlHelper class in razor view instead of writing HTML tags manually.
7- What are RESTfull APIs?
REST stands for REpresentational State Transfer. REST is a web standards-based architecture and uses HTTP Protocol for data communication. It revolves around resources where every component is a resource and a resource is accessed by a common interface using HTTP standard methods
In REST architecture, a REST Server simply provides access to resources, and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON, and XML. Nowadays JSON is the most popular format being used in web services.
8- What is Output Caching in MVC?
It enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked. Output Caching has huge advantages, such as it reduces server round trips, reducing database server round trips, reducing network traffic, etc. The main purpose of using Output Caching is to improve the performance of the application.
9- What are Bundling and Minification in MVC?
Bundling and minification are two techniques you can use to improve request load time.
Bundling helps you to download files of the same type using one request instead of multiple requests. This way you can download styles and scripts using fewer requests than it takes to request all files separately.
Minification performs a variety of different code optimizations to scripts or CSS, such as removing unnecessary white space, and comments and shortening variable names to one character.
10- What is Partial View in MVC?
A partial view is a component built by the developer to reuse a bulk of HTML that can be inserted into an existing DOM. Most commonly, partial views are used to componentize Razor views and make them easier to build and update. Partial views can also be returned directly from controller methods.