What is the full form of MVC?
MVC is generally abbreviated as Model View Controller.
What do you understand by Model View Control?
“MVC is a software architecture or application design model containing 3 interconnected verticals or portions. These 3 portions are the model (data associated with the application), the view (which is the user interface of an MVC application), and the controller (the processes that are responsible for handling the input).
The MVC model is normally used to develop modern applications with user interfaces. It provides the central pieces for designing a desktop or mobile application, as well as modern web applications.”
Explain Model, View and Controller in brief
“A model can be defined as the data that will be used by the program. Commonly used examples of models in MVC are the database, a simple object holding data (such as any multimedia file or the character of a game), a file, etc.
A view is a way of displaying objects (user interfaces) within an application. This is the particular vertical through which end users will communicate.
A controller is the third vertical which is responsible for updating both models and views. It accepts input from users as well as performs the equivalent update. In other words, it is the controller which is responsible for responding to user actions.
ASP.NET MVC Interview
What are the different return types used by the controller action method in MVC?
“The various return types of controller action methods in MVC are:
View Result
JSON Result
Content Result
Redirect Result
JavaScript Result”
Name the assembly in which the MVC framework is typically defined.
In the System.Web.Mvc, the MVC framework is usually defined.
Explain the MVC Application life cycle.
“The web applications usually have 2 primary execution steps. These are:
Understanding the request
Sending an appropriate response based on the type of request
The same thing can be related to MVC applications also whose life cycle has 2 foremost phases:
for creating a request object
for sending the response to any browser
Advance ASP.Net MVC Interview
What are the various steps to create the request object?
“In order to create a request object, we have to go through 4 different steps. These are –
Step 1: Fill the route
Step 2: Fetch the route
Step 3: Create a request context
Step 4: Create a controller instance
Explain some benefits of using MVC?
“Some common benefits of MVC are –
Support of multiple views: Since there is a separation of the model from its view, the user interface (UI) gets the capability to implement multiple views of the same data concurrently.
Faster development process: MVC has the ability to provide rapid and parallel development. This means that while developing an application, it is more likely that one programmer will perform some action on the view and in parallel, another can work on creating the application’s business logic.
SEO-friendly development: The platform of MVC can support SEO-friendly development of web pages or web applications.
More Control: The MVC framework (of ASP.NET) offers additional control over HTML, CSS and JavaScript than that of traditional Webworm’s.
Lightweight: MVC framework does not make use of View State which eventually minimizes the requested bandwidth to some extent.
Explain in brief the role of different MVC components?
“The different MVC components have the following roles –
Presentation: This component takes care of the visual representation of a particular abstraction in the application.
Control: This component takes care of the consistency and uniformity between the abstraction within the system along with their presentation to the user. It is also responsible for communicating with all other controls within the MVC system.
Abstraction: This component deals with the functionality of the business domain within the application.
ASP.Net MVC Interview
How will you maintain the sessions in MVC?
“The sessions of an MVC can be maintained by 3 possible ways:
view data
temp data and
view bag
What do you mean by partial view of MVC?
“A partial view can be defined as a portion of HTML that is carefully injected into an existing DOM. Partial views are commonly implemented for componentizing Razor views, making them simpler to build and update. Controller methods can also directly return the partial views.
Explain in brief the difference between adding routes in a webform application & an MVC application?
We make use of the Map Page Route() which is of the Route Collection class for adding routes in a webform application. Whereas, the Map Route() method is used for adding routes to an MVC application.
Advance ASP.Net MVC Interview
How will you define the 3 logical layers of MVC?
“The 3 logical layers of MVC can be defined as follows:
Model logic which acts as a business layer
View logic which acts as a display layer
Controller logic acts as input control”
What is the use of Action Filters in MVC?
Action Filters are used for executing the logic while MVC action is executed. Furthermore, action filters permit the implementation of pre and post-processing logic and action methods.
How to execute any MVC project? Explain its steps.
“For executing an MVC project, the steps followed are –
Receive the first request for the application
Then, the routing is performed
Then, the MVC request handler is created
After that, the controller is created and executed
Then, the action is invoked
Then, the results are executed
ASP.Net MVC Interview
What is the concept of routing in MVC?
MVC routing can be defined as a pattern-matching scheme that is used for mapping incoming requests of browsers to a definite MVC controller action.
What are the 3 important segments for routing?
“The 3 important segments for routing are:
Controller Name
Action Method Name
Parameter
What are the different properties of MVC routes?
“MVC routes are accountable for governing which controller method will be executed for a given URL. Thus, the URL comprises of the following properties:
Route Name: It is the URL pattern which is used for mapping the handler.
URL Pattern: It is another property containing the literal values as well as variable placeholders (known as URL parameters).
Defaults: This is the default parameter value assigned at the time of parameter creation.
Constraints: These are used for applying against the URL pattern for more narrowly defining the URL matching it.
Advance ASP.NET MVC Interview
How is the routing carried out in MVC?
The Route Collection contains a set of routes that are responsible for registering the routes in the application. The Register Routes method is used for recording the routes in the collection. The URL patterns are defined by the routes and a handler is used which checks the request matching the pattern. The MVC routing has 3 parameters. The first parameter determines the name of the route. The second parameter determines a specific pattern with which the URL matches. The third parameter is responsible for providing default values for its placeholders.
How will you navigate from one view to another view in MVC? Explain with a hyperlink example
“We will make use of the Action Link method which will help us to navigate from one view to another. Here is an example of navigating the Home controller by invoking the Go to Home action.
He is how we can code it:
<%=Html.ActionLink(""Home"",""GoTo Home"")%>
"
Explain the 3 concepts in one line; Temp data, View, and View bag?
“We can briefly describe Temp data, View, and View bag as:
Temp data: This is used for maintaining the data when there is a shift of work from one controller to another.
View data: This is used for maintaining the data when we will shift from a controller to a view within an application.
View Bag: This acts as a view data’s dynamic wrapper.”
ASP.Net MVC Interview
Mention & explain the different approaches you will use to implement Ajax in MVC?
“There are 2 different approaches to implement Ajax in MVC. These are:
jQuery: This is a library written using JavaScript for simplifying HTML-DOM manipulation.
AJAX libraries: Asynchronous JavaScript and XML libraries are set of web development libraries written using JavaScript and are used to perform common operations.”
What is Spring MVC?
The Spring MVC or Spring Web MVC can be defined as a framework that provides a “Model View Controller” (MVC) architecture in the application as well as ready-components implemented for developing adjustable and adaptable web applications. It is actually a Java-based framework intended to build web applications. It works on the Model-View-Controller design approach. This framework also makes use of all the elementary traits of a core Spring Framework such as dependency injection, light-weight, integration with other frameworks, inversion of control, etc. Spring MVC has a dignified resolution for implementing MVC in Spring Framework with the use of Dispatcher Servlet.
Explain briefly what you understand by separation of concern.
Separation of Concerns can be defined as one of the core features as well as benefits of using MVC and is supported by ASP.NET. Here, the MVC framework offers a distinct detachment of the different concerns such as User Interface (UI), data and the business logic.
Advance ASP.Net MVC Interview
Define Output Caching in MVC?
“Output Caching is an approach used for improving the performance of an MVC application. It is used for enabling its users to cache the data sent back by the controller method so that the data used earlier does not get generated each time while invoking the same controller method. It has advantages to use Output Caching as it cuts down database server round trips, minimizes server round trips as well as reduces the network traffic.
Why are Manufacturer and Bundling introduced in MVC?
Two new techniques have been included in MVC, known as Bundling and minification, whose primary function is to progress the request load time. It advances the load time by dipping the quantity of requests sent to the server as well as reducing the requested asset’s (JavaScript and CSS) size.
Describe ASP.NET MVC?
The term ASP.NET MVC can be defined as a web application framework that is very lightweight and has high testable features. ASP.NET supporting MVC uses 3 separate components in its application. These are the Model, View, and Controller.
ASP.Net MVC Interview
Define the concept of Filters in MVC?
“There are situations where I want to implement some logic either prior to the execution of the action method or right after it. In that scenario, the Action Filters are used. Filters are used to determine the logic needed for executing before or after the action method gets executed. Action methods make use of the action filters as an attribute. Different types of MVC action filter are:
Action filter (that implements the IActionFilter)
Exception filter (that implements the IExceptionFilter attribute)
Authorization filter (that implements the IAuthorizationFilter)
Result filter (that implements the IResultFilter)
Mention the significance of Nonaction Attribute?
The various public methods that are associated with the controller class are considered to be the action method. For preventing the default method, you have to allocate its public method with Nonaction Attribute.
When multiple filters are used in MVC, how is the ordering of execution of the filters done?
“The order in which filters are used –
First, the authorization filters are executed
Followed by the Action filters
Then, the response filters are executed
Finally, the exception filters
Advance ASP.Net MVC Interview
Mention the possible file extensions used for razor views?
“The different file extensions that are used by razor views are:
.cshtml: When your MVC application is using C# as the programming language.
.vbhtml: When your MVC application is using VB is the programming language.”
Explain briefly the 2 approaches of adding constraints to an MVC route?
“For adding constraints to an MVC route, the 2 different approaches are:
By making use of regular expressions
By making use of objects that implement the “IRouteConstraint” interface.
Point out the different stages a Page life cycle of MVC has?
“The different steps or stages of page life-cycle of MVC are:
Initialization of app
Routing
Instantiate the object followed by executing the controller
Locate as well as invoke the controller action
Instantiating and then rendering the view
ASP.Net MVC Interview
Explain briefly the use of View Model in MVC?
“View Model can be defined as a plain class having different properties. It is used for binding a view that is strongly-typed. View Model consists of various validation rules for defining the properties of practicing data annotation.
Define Default Route in MVC?
“The default Route of project templates in MVC includes a generic route that makes use of the given URL resolution for breaking the URL based on the request into 3 tagged segments. URL: “{controller} / {action} / {id}”
What are the rules of Razor syntax?
The primary rules for creating Razor are:
The block of Razor codes is enclosed within @{ … }
Variables and functions of inline expressions start with @ symbol.
The ‘var’ keyword is used for declaring variables
Razor code statements are terminated with a semicolon
C# files have .cshtml as file extension”
Advance ASP.Net MVC Interview
What are the areas of benefits in using MVC?
“The area of benefits of using MVC is:
Unit testing becomes much easier.
It permits its users to shape views, models, and controllers into 3 distinct operational sections within an application.
It becomes easy to assimilate with other areas produced by another application.
Point out the different approaches for adding constraints to a route?
“There are 2 different methods used for adding constraints to the route. These are:
By implementing the regular expressions
By making use of an object implementing the IRouteConstraint interface
Point out the 2 instances where you cannot use routing or where routing is not necessary?
“The 2 situations where routing is not used or not necessary are:
When there is a physical file matching the URL pattern
When any routing gets disabled in any particular URL pattern”
ASP.Net MVC Interview
How will you explain the concept of Render Body and Render Page of MVC?
“Render Body can be considered as a Content Placeholder of web forms. It is available in the layout page and will be responsible for rendering the child pages/views. On the other hand, the layout page contains a single Render Body() method. Multiple Render Page() can reside within the Layout page.
Explain what is the difference between View and Partial View?
“View
It contains the layout page.
Before any view is rendered, view start page is rendered.
A view might have markup tags like body, HTML, head, title, meta etc.
The view is not lightweight as compare to Partial View.
Partial View
It does not contain the layout page.
Partial view does not verify for a We cannot put common code for a partial view within the viewStart.cshtml.page.
Partial view is designed specially to render within the view and just because of that it does not consist any mark up.
We can pass a regular view to the Render Partial method.”
Explain attribute based routing in MVC?
“In ASP.NET MVC 5.0 we have a new attribute router By using the “”Route”” attribute we can define the URL structure. For example in the below code we have decorated the “”Go to About”” action with the route attribute. The route attribute says that the “”Go to About”” can be invoked using the URL structure “”Users/about””.
Hide Copy Code
public class HomeController: Controller
{
[Route(“”Users/about””)]
publicActionResultGotoAbout()
{
return View();
}
} “
Advance ASP.Net MVC Interview
What is Temp Data in MVC?
“Temp Data is a dictionary object to store data temporarily. It is a Temp Data Dictionary class type and instance property of the Controller base class.
Temp Data is able to keep data for the duration of a HTP request, in other words it can keep live data between two consecutive HTTP requests. It will help us to pass the state between action methods. Temp Data only works with the current and subsequent request. Temp Data uses a session variable to store the data. Temp Data Requires type casting when used to retrieve data.
Temp Data Dictionary is inherited from the IDictionary, ICollection>, IEnumerable> and IEnumerable interfaces.
Example
public ActionResult FirstRequest()
{
List < string > TempDataTest = new List < string > ();
TempDataTest.Add(“”Tejas””);
TempDataTest.Add(“”Jignesh””);
TempDataTest.Add(“”Rakesh””);
TempData[“”EmpName””] = TempDataTest;
return View();
}
public ActionResult ConsecutiveRequest()
{
List < string > modelData = TempData[“”EmpName””] as List < string > ;
TempData.Keep();
return View(modelData);
} “
What are the two ways to add constraints to a route?
“The two methods to add constraints to a route is
Use regular expressions
Use an object that implements IRouteConstraint Interface”
What “before Filter()”,”before Render” and “after Filter” functions do in Controller?
“before Filter(): This function runs before every action in the controller. It’s the right place to check for an active session or inspect user permissions.
before Render(): This function is called after controller action logic, but before the view is rendered. This function is not often used but may be required if you are calling render() manually before the end of a given action.
after Filter(): This function is called after every controller action and after rendering is done. It is the last controller method to run.”
ASP.Net MVC Interview