January 14, 2019

Srikaanth

Nate Frequently Asked ASP.NET MVC Interview Questions Answers

What Are Scaffold Templates In Asp.net Mvc?

Scaffolding in ASP.NET ASP.Net MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.

Explain The Types Of Scaffoldings?

Below are the types of scaffoldings

Empty
Create
Delete
Details
Edit
List

Can A View Be Shared Across Multiple Controllers? If Yes, How We Can Do That?

Yes we can share a view across multiple controllers. We can put the view in the "Shared" folder. When we create a new ASP.Net MVC Project we can see the Layout page will be added in the shared folder, which is because it is used by multiple child pages.

What Are The Components Required To Create A Route In Asp.net Mvc?

Name - This is the name of the route.

URL Pattern : Placeholders will be given to match the request URL pattern.

Defaults :When loading the application which controller, action to be loaded along with the parameter.

Why To Use "{resource}.axd/{*pathinfo}" In Routing In Asp.net Mvc?

Using this default route - {resource}.axd/{*pathInfo}, we can prevent the requests for the web resources files like - WebResource.axd or ScriptResource.axd from passing to a controller.

Can We Add Constraints To The Route? If Yes, Explain How We Can Do It?

Yes we can add constraints to route in following ways

Using Regular Expressions
Using object which implements interface - IRouteConstraint.
Nate Frequently Asked ASP.NET MVC Interview Questions Answers
Nate Frequently Asked ASP.NET MVC Interview Questions Answers

What Are The Possible Razor View Extensions?

Below are the two types of extensions razor view can have

.cshtml : In C# programming language this extension will be used.

.vbhtml - In VB programming language this extension will be used.

What Is Partialview In Asp.net Mvc?

PartialView is similar to UserControls in traditional web forms. For re-usability purpose partial views are used. Since it's been shared with multiple views these are kept in shared folder.

Partial Views can be rendered in following ways

Html.Partial()
Html.RenderPartial()

How We Can Add The Css In Asp.net Mvc?

Below is the sample code snippet to add css to razor views : < link rel="StyleSheet" href="/@Href(~Content/Site.css")" type="text/css"/>

Can I Add Asp.net Mvc Testcases In Visual Studio Express?

No. We cannot add the test cases in Visual Studio Express edition it can be added only in Professional and Ultimate versions of Visual Studio.

What Is The Use .glimpse In Asp.net Mvc?

Glimpse is an open source tool for debugging the routes in ASP.Net MVC. It is the client side debugger. Glimpse has to be turned on by visiting to local url link - http://localhost:portname//glimpse.axd This is a popular and useful tool for debugging which tracks the speed details, url details etc.

What Are Model Binders In Asp.net Mvc?

For Model Binding we will use class called : "ModelBinders", which gives access to all the model binders in an application. We can create a custom model binders by inheriting "IModelBinder".

How We Can Handle The Exception At Controller Level In Asp.net Mvc?

Exception Handling is made simple in ASP.Net MVC and it can be done by just overriding "OnException" and set the result property of the filtercontext object (as shown below) to the view detail, which is to be returned in case of exception.

protected overrides void OnException(ExceptionContext filterContext)

    {

    }

How We Can Invoke Child Actions In Asp.net Mvc?

"ChildActionOnly" attribute is decorated over action methods to indicate that action method is a child action. Below is the code snippet used to denote the child action

[ChildActionOnly]

public ActionResult MenuBar()

{

//Logic here

return PartialView();

}

What Is Dependency Injection In Asp.net Mvc?

it's a design pattern and is used for developing loosely couple code. This is greatly used in the software projects. This will reduce the coding in case of changes on project design so this is vastly used.

Explain The Advantages Of Dependency Injection (di) In Asp.net Mvc?

Below are the advantages of DI

Reduces class coupling
Increases code reusing
Improves code maintainability
Improves application testing

Does Tempdata Hold The Data For Other Request In Asp.net Mvc?

If Tempdata is assigned in the current request then it will be available for the current request and the subsequent request and it depends whether data in TempData read or not. If data in Tempdata is read then it would not be available for the subsequent requests.

Explain Keep Method In Tempdata In Asp.net Mvc?

As explained above in case data in Tempdata has been read in current request only then "Keep" method has been used to make it available for the subsequent request.

@TempData["TestData"];

TempData.Keep("TestData");

Explain Peek Method In Tempdata In Asp.net Mvc?

Similar to Keep method we have one more method called "Peek" which is used for the same purpose. This method used to read data in Tempdata and it maintains the data for subsequent request.

string A4str = TempData.Peek("TT").ToString();

What Is Area In Asp.net Mvc?

Area is used to store the details of the modules of our project. This is really helpful for big applications, where controllers, views and models are all in main controller, view and model folders and it is very difficult to manage.

How We Can Register The Area In Asp.net Mvc?

When we have created an area make sure this will be registered in "Application_Start" event in Global.asax.

Below is the code snippet where area registration is done

protected void Application_Start()

{

AreaRegistration.RegisterAllAreas();

}

What Are Child Actions In Asp.net Mvc?

To create reusable widgets child actions are used and this will be embedded into the parent views. In ASP.Net MVC Partial views are used to have reusability in the application. Child action mainly returns the partial views.

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.

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.

https://mytecbooks.blogspot.com/2019/01/nate-frequently-asked-aspnet-mvc.html
Subscribe to get more Posts :