Spotify Technology Frequently Asked ASP.NET MVC Interview Questions Answers

Explain Test Driven Development (tdd) ?

TDD is a methodology which says, write your tests first before you write your code. In TDD, tests drive your application design and development cycles. You do not do the check-in of your code into source control until all of your unit tests pass.

Explain The Tools Used For Unit Testing In Asp.net Mvc?

Below are the tools used for unit testing

NUnit
xUnit.NET
Ninject 2
Moq

What Is Representational State Transfer (rest) Mean?

REST is an architectural style which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the data. ASP.Net MVC works in this style. In ASP.Net MVC 4 there is a support for Web API which uses to build the service using HTTP verbs.

How To Return The Json From Action Method In Asp.net Mvc?

Below is the code snippet to return string from action method

public ActionResult TestAction() {

return JSON(new { prop1 = "Test1", prop2 = "Test2" });

}

How Does The 'page Lifecycle' Of Asp.net Mvc Works?

Below are the processed followed in the sequence

App initializWhat is Separation of Concerns in ASP.NET ASP.Net MVCation
Routing
Instantiate and execute controller
Locate and invoke controller action
Instantiate and render view.
Spotify Technology Frequently Asked ASP.NET MVC Interview Questions Answers
Spotify Technology Frequently Asked ASP.NET MVC Interview Questions Answers

Explain The Advantages Of Asp.net Mvc Over Asp.net?

Provides a clean separation of concerns among UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
Easy to UNIT Test.
Improved reusability of model and views. We can have multiple views which can point to the same model and vice versa.
Improved structuring of the code.

What Is Separation Of Concerns In Asp.net Asp.net Mvc?


It is the process of breaking the program into various distinct features which overlaps in functionality as little as possible. ASP.Net MVC pattern concerns on separating the content from presentation and data-processing from content.

List out few different return types of a controller action method?

View Result
Javascript Result
Redirect Result
Json Result
Content Result

Mention what is the difference between adding routes, to a webform application and an MVC application?

To add routes to a webform application, we can use MapPageRoute() method of the RouteCollection class, where adding routes to an MVC application, you can use MapRoute() method.

Mention 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

Mention two instances where routing is not implemented or required?

Two instance where routing is not required are

When a physical file is found that matches the URL pattern
When routing is disabled for a URL pattern

Mention what are main benefits of using MVC?

There are two key benefits of using MVC

As the code is moved behind a separate class file, you can use the code to a great extent
As behind code is simply moved to.NET class, it is possible to automate UI testing. This gives an opportunity to automate manual testing and write unit tests.

Mention what is the advantages of MVC?

MVC segregates your project into a different segment, and it becomes easy for developers to work on
It is easy to edit or change some part of your project that makes project less development and maintenance cost
MVC makes your project more systematic

Mention what “beforFilter()”,“beforeRender” and “afterFilter” functions do in Controller?

beforeFilter(): This function is run before every action in the controller. It’s the right place to check for an active session or inspect user permissions.
beforeRender(): 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
afterFilter(): This function is called after every controller action, and after rendering is done. It is the last controller method to run

Explain the role of components Presentation, Abstraction and Control in MVC?

Presentation: It is the visual representation of a specific abstraction within the application
Abstraction: It is the business domain functionality within the application
Control: It is a component that keeps consistency between the abstraction within the system and their presentation to the user in addition to communicating with other controls within the system

Explain the role of “ActionFilters” in MVC?

In MVC “ ActionFilters” help you to execute logic while MVC action is executed or its executing.

Explain what are the steps for the execution of an MVC project?

The steps for the execution of an MVC project includes

Receive first request for the application
Performs routing
Creates MVC request handler
Create Controller
Execute Controller
Invoke action
Execute Result

Explain what is Model-View-Controller?

MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller.

Mention what does Model-View-Controller represent in an MVC application?

In an MVC model,

Model– It represents the application data domain. In other words applications business logic is contained within the model and is responsible for maintaining data
View– It represents the user interface, with which the end users communicates. In short all the user interface logic is contained within the VIEW
Controller– It is the controller that answers to user actions. Based on the user actions, the respective controller responds within the model and choose a view to render that display the user interface.  The user input logic is contained with-in the controller

Explain in which assembly is the MVC framework is defined?

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

Explain what is routing? What are the three segments for routing is important?

Routing helps you to decide a URL structure and map the URL with the Controller.

The three segments that are important for routing is

ControllerName
ActionMethodName
Parameter

Mention what is the difference between “ActionResult” and “ViewResult” ?

“ActionResult” is an abstract class while “ViewResult” is derived from “AbstractResult” class.  “ActionResult” has a number of derived classes like “JsonResult”, “FileStreamResult” and “ViewResult” .

“ActionResult” is best if you are deriving different types of view dynamically.

Explain how you can send the result back in JSON format in MVC?

In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.

List out the types of result in MVC?

In MVC, there are twelve types of results in MVC where “ActionResult” class is the main class while the 11 are their sub-types

ViewResult
PartialViewResult
EmptyResult
RedirectResult
RedirectToRouteResult
JsonResult
JavaScriptResult
ContentResult
FileContentResult
FileStreamResult
FilePathResult

Mention what is the importance of NonActionAttribute?

All public methods of a controller class are treated as the action method if you want to prevent this default method then you have to assign the public method with NonActionAttribute.

Mention what is the use of the default route {resource}.axd/{*pathinfo} ?

This default route prevents request for a web resource file such as Webresource.axd or ScriptResource.axd from being passed to the controller.

Mention the order of the filters that get executed, if the multiple filters are implemented?

The filter order would be like

Authorization filters
Action filters
Response filters
Exception filters

Explain how routing is done in MVC pattern?

There is a group of routes called the RouteCollection, which consists of registered routes in the application.  The RegisterRoutes method records the routes in this collection.  A route defines a URL pattern and a handler to use if the request matches the pattern. The first parameter to the MapRoute method is the name of the route. The second parameter will be the pattern to which the URL matches.  The third parameter might be the default values for the placeholders if they are not determined.

Explain using hyperlink how you can navigate from one view to other view?

By using “ActionLink” method as shown in the below code. The below code will make a simple URL which help to navigate to the “Home” controller and invoke the “GotoHome” action.

Collapse / Copy Code

<%= Html.ActionLink(“Home”, “Gotohome”) %>

Mention what filters are executed in the end?

In the end “Exception Filters” are executed.

Mention what are the file extensions for razor views?

For razor views the file extensions are

.cshtml: If C# is the programming language
.vbhtml: If VB is the programming language

Mention what are the two ways for adding constraints to a route?

Two methods for adding constraints to route is

Using regular expressions
Using an object that implements IRouteConstraint interface

Mention how can maintain session in MVC?

Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.

Mention what is the difference between Temp data, View, and View Bag?

Temp data: It helps to maintain data when you shift from one controller to other controller.
View data: It helps to maintain data when you move from controller to view
View Bag: It’s a dynamic wrapper around view data

What is partial view in MVC?

Partial view in MVC renders a portion of view content. It is helpful in reducing code duplication. In simple terms, partial view allows to render a view within the parent view.

Explain how you can implement Ajax in MVC?

In Ajax, MVC can be implemented in two ways

Ajax libraries
Jquery.

What is ASP.NET MVC?

ASP.NET MVC is a web application Framework. It is light weight and highly testable Framework. MVC separates application into three components — Model, View and Controller.

What is Razor View Engine?

Razor is the first major update to render HTML in MVC 3. Razor was designed specifically for view engine syntax. Main focus of this would be to simplify and code-focused templating for HTML generation. Below is the sample of using Razor:

@model MvcMusicStore.Models.Customer
@{ViewBag.Title = “Get Customers”;}
<div class=”cust”> <h3><em>@Model.CustomerName</em> </h3>

What you mean by Routing in MVC?

Routing is a pattern matching mechanism of incoming requests to the URL patterns which are registered in route table. Class — “UrlRoutingModule” is used for the same process.

What are Actions in MVC?

Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type — “ActionResult” and it will be invoked from method — “InvokeAction()” called by controller.

What is Attribute Routing in MVC?

ASP.NET Web API supports this type routing. This is introduced in MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like –

[Route(“{action = TestCategoryList}”)] — Controller Level
[Route(“customers/{TestCategoryId:int:min(10)}”)] — Action Level

How to enable Attribute Routing?

Just add the method — “MapMvcAttributeRoutes()” to enable attribute routing as shown below

public static void RegistearRoutes(RouteCollection routes)

{

routes.IgnoareRoute(“{resource}.axd/{*pathInfo}”);

//enabling attribute routing

routes.MapMvcAttributeRoutes();

//convention-based routing

routes.MapRoute

(

name: “Default”,

url: “{controller}/{action}/{id}”,

defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }

);

}

Post a Comment

Previous Post Next Post