TOP 50 ASP.NET MVC Interview Questions and Answers

Here we will see some basic and most important questions related to interview in ASP.NET MVC.

Question 1: What is ASP.NET MVC?

Its stand for Model, View, and Controller. It is a web application framework which is lightweight and secure.

Question 2: What is Model, Controller, and View in MVC?

Model – It normally contains class and represent the application data.

Controller – It is the main class which communicates with user request and as per request return response to the user.

View – It is the web page from the user send a request to the controller. (designing page).

Question 3: What is the page life cycle of MVC?

It’s processed by the below sequence:

  1. Initialize App
  2. Routing
  3. Execute controller
  4. Find and execute an action
  5. Return view.

Question 4: What are the advantages of MVC over ASP.NET?

  1. Code separation
  2. Faster development
  3. Support asynchronous technique
  4. Easy to Modify without affect the entire model
  5. SEO friendly
  6. Easy integration with JavaScript frameworks.
  7. No PostBack events
  8. Loosely coupled tiers

Question 5: What is the Razor View Engine?

Razor is a markup syntax that helps to embed server-based code into web pages. It is a server-side markup language and It is not a programming language.

Question 6: What are the Actions in MVC?

In simple word, all public methods of a Controller class are called Action methods.It is responsible to execute requests and generate and return responses for that request. Default, it generates a response in the form of ActionResult.

Question 7: What is a Bundle.Config?

It is used to register the bundles, minification and versioning CSS and Javascript files. In short, it combines multiple files into a single file.

Question 8: What is ViewData?

It is one kind of holder and that holds the data and passed from controller to view.

Question 9: What is the Layout in ASP.Net MVC?

It is similar to the master page concept in asp.net to provide a uniform look in the whole application.

             Syntax:

             @{

                  Layout = “~/Views/Shared/MyLayout.cshtml”;

                  }

Question 10: What are the types of ActionResult?

  • ViewResult
  • RedirectToRouteResult
  • JSONResult
  • PartialViewResult
  • FileResult
  • RedirectResult
  • JavascriptResult
  • HTTPStatusCodeResult

Question 11: What is Area in ASP.Net MVC?

In a simple word it helps and used for large application Where too many numbers of controller and view. The area is basically group and separates this thing. One application can have any number of Areas and each Area has its own controllers, models, and views. When we created the Area.

Question 12: what is the default http method for an action method in MVC ?

HttpGet

Question 13: Which common parts of UI view contains?

Layout view

Question 14: What is action filters?

It executes before and after action method executes.

Question 15: Can We use Razor code in JavaScript in ASP.Net MVC? If  yes, then How? And no then Why?

Yes. We can use the razor code in JavaScript in cshtml by using <text> element or @ sign.

Syntax:

<script type=”text/javascript”>

   @foreach (var item in Model) {

<text>

//javascript code

</text>

   }

</script>

Question 16: What is a partial view in MVC?

Its similar to user control in ASP.NET.It is a piece of HTML that can be safely inserted into an existing DOM.

Question 17: What is/are disadvantages of ASP.NET MVC?

It depends on the type of project. Some others are

  • Knowledge of multiple technologies is required.
  • Inefficiency of data access in view
  • No any In-built controls.

Question 18: What are the possible Razor view extensions?

  • .cshtml in C#
  • .vbhtml in VB

Question 19: What are the Scaffold templates in MVC?

It’s a boilerplate to generate the Controllers, Model, and Views for creating, read, update, and delete functionality in an application.

Question 20: What is TempData in MVC?

Its store temporary data which can be used in the subsequent request. It will automatically be deleted once a subsequent request is completed.

Question 21: How many approaches are there in Entity Framework?     

There are three approaches:   Code First, Model First, and Database First.

 Question 22: What is model first approach in MVC?

In Model First approach first, we need to create Entities and write relationship on the design surface of EDMX and then it will generate database from it.

Question 23: What is code first approach in MVC?

In Code First approach first, we need to create classes (must match database design) which generate table in database.

Question 24: What is database first approach in MVC?

In database First approach first, we need to create database and tables and based on that entity framework create classes from an existing database.

Question 25: What is latest version of MVC?

MVC 6 is the latest version which is also termed as ASP VNEXT.

Question 26: What is the meaning of strongly typed view in MVC?

Strongly typed View is one that is generated /associated with a Model.

Question 27: What are features of Strongly Typed Views?

  1. Type checking while compile
  2. Intellisense support
  3. Automatic scaffolding

Question 28: Can we map multiple URLs with same Action?

Yes, we can, we just need to make two entries with unique key names and specify the same controller and action.

Question 29:  Where routing code is written?

In RouteConfig.cs file.

Question 30: how can maintain session in MVC?

There are three ways

  1. tempdata
  2. viewdata
  3. viewbag

Question 31:  Which filters are executed at the end?

“Exception Filters” are executed in the end.

Question 32: How many ways for adding constraints to a route?

There are two methods

  • Using regular expressions
  • Using an object that implements IRouteConstraint interface

Question 33: What is the difference between these two methods, RenderAction and RenderPartial?

RenderAction will call an action method of the controller and render a result and RenderPartial will render the specified view without execute/call any action method.

Question 34: What is Output Caching in MVC?

It enables to cache the content returned by controller method so that the same content won’t be generated each time the same controller method is invoked.

Question 35: What is Validation Summary in MVC?

It generates an unordered list of validation messages that are in the ModelStateDictionary object.

Question 36: How to Change the Action Name in Asp.net Mvc? 

“ActionName” attribute is used to changing the action name.

Example

         [ActionName(“UpdatedName”)]

         public ActionResult Name()     {

           return View();

        }

Question 37: What are types of Scaffoldings?

  • Empty
  • Create
  • Delete
  • Details
  • Edit
  • List

Question 38: Is that possible to add/use Multiple Submit Buttons in Asp.net Mvc?

Yes, we can, we just need to add unique value.

Question 39: What is REST full form?

REST stands for Representational State Transfer.

Question 40: Can we create own custom view engine in MVC?

Yes, we can create

Question 41: What is “WebAPI”?

It is a framework that you can make use of to build web services that use HTTP as the protocol.

Question 42: How to return the JSON from action method in ASP.Net MVC?

public ActionResult MyAction(){

return JSON(new { data = “response” }, JsonRequestBehavior.AllowGet);

}

Question 43: Can we use ViewState in MVC?

This is common question to judge your knowledge about MVC. MVC does not have viewstate.

Question 44: How do we generate hyperlink?

@Html.ActionLink(“hyperlink text”, “Controller”, “Action”)

Question 45: What is Bootstrap in MVC?

Bootstrap is an open source front-end framework to design application.

Question 46:  Which filters are executed in the first?

“Authorization Filters” are executed in the first.

Question 47: Who introduce MVC to the world?

Trygve Reenskaug

Question 48: What is alternative of View State in MVC?

we can use Ajax and TempData.

Question 49: Can we use C# without .net?

yes, we can, C# is just a programming language.

Question 50: Can we use ASPX view engine in latest versions of MVC?

Yes. But Recommended way is to prefer Razor View.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories