Interview Questions.

ASP.NET MVC Interview Questions and Answers


ASP.NET MVC Interview Questions and Answers

Q1. What is MVC

Ans: Model–view–controller (MVC) is a software layout sample for enforcing consumer interfaces on computers. It divides a given software application into three interconnected components, that allows you to separate internal representations of records from the methods that information is offered to or widespread from the consumer.

Q2. As an ASP.NET MVC is a framework for building web packages the usage of a MVC (Model View Controller) ?

Ans: A Model , which represents the underlying, logical structure of records in a software program utility and the high-stage magnificence associated with it. This object model does not comprise any information about the consumer interface.

A View , that is a group of classes representing the factors within the person interface (all the things the person can see and respond to at the display screen, inclusive of buttons, show containers, and so on)

A Controller , which represents the lessons connecting the model and the view, and is used to speak among classes in the version and consider. The MVC version additionally affords complete manage over HTML, CSS, and JavaScript.

Q3. Can you explain the complete glide of MVC?

Ans: Below are the stairs how control flows in MVC (Model, view and controller) architecture:-

1.All quit person requests are first sent to the controller.

2.The controller relying at the request decides which version to load. The controller hundreds the model and attachesthe model with the correct view.

Three.The very last view is then connected with the model statistics and sent as a reaction to the cease person on the browser

Q4. What are the specific kinds of motion outcomes in MVC?

Ans: In MVC there are 12 outcomes. Among them ActionResult elegance is a base magnificence for all motion results. The eleven sub instructions are given bellow:

ViewResult– renders a view as an internet page to the reaction circulation

PartialViewResult– renders a view inside every other view

EmptyResult– returns a empty or null end result

RedirectResult– redirect to another movement technique (HTTP redirection)

RedirectToRouteResult– redirect to every other movement method (HTTP redirection) that is determined by the routing engine, primarily based on a given direction

JsonResult– returns a JSON item shape a ViewData

JavaScriptResult– returns a script code that can be completed on the patron

ContentResult– returns a consumer-defined content material type

FileContentResult– returns a document to the patron

FileStreamResult– returns a report to the consumer, that is furnished by using a Stream

FilePathResult– returns a document to the purchaser

Q5. What are routs in MVC and in which to configure it?

Ans: Routing is a manner to manner the incoming url that is greater descriptive and provide favored reaction. A route is a URL pattern that is mapped to a handler. The handler can be a bodily record, which include a .Aspx document in a Web Forms application. A handler also can be a category that processes the request, inclusive of a controller in an MVC software. To define a course, you create an example of the Route elegance with the aid of specifying the URL sample, the handler, and optionally a call for the route.

Q6. Explain the difference among three-layer structure and MVC structure.

Ans: MVC is an evolution of a 3 layered traditional architecture. Many additives of the 3 layered structure are the a part of MVC.

A essential rule in three tier architecture is the customer tier in no way communicate at once with the facts tier. In a 3-tier model all communication need to pass via the middle tier.

MVC structure is triangular. The view sends updates to the controller, the controller updates the version, and the view receives updated without delay from the model.

Q7. What Are Action Filters in MVC?

Ans: Action Filters: Action filters are used to put in force common sense that receives completed earlier than and after a controller motion executes.

Q8. Is MVC appropriate for both home windows,and net application?

Ans: MVC architecture is suitable for internet application than home windows. For window utility MVP i.E. “Model view presenter”is more relevant.IfyouareusingWPFandSLMVVMismoresuitableduetobindings

Q9. What is Razor Engine and the way it works?

Ans: Razor ia an ASP MVC view engine that helps you to to jot down server-primarily based code on your view to create a dynamic content material the render it into availd HTML

HubSpot Video

Q10.How to enforce Windows authentication in MVC?

Ans: For Windows authentication, before everything we want to change the web.Config document and set the authentication mode to Windows. A sample code for this is given bellow:

<authentication mode="Windows"/>


<deny users="?"/>


Then within the controller or on the motion, we are able to use the Authorize attribute which specifies which customers have get admission to to these controllers and moves. A sample code for this is given bellow, wherein simplest the user “Administrator” can get entry to it.

[Authorize(Users= @”WIN-3LI600MWLQNAdministrator”)]

public magnificence StartController : Controller


// GET: /Start/

[Authorize(Users = @"WIN-3LI600MWLQNAdministrator")]

public ActionResult Index()

go back View("MyView");

Q11. Mention three methods to pass facts among the controllers and views, and while to apply every of them?

Ans: ViewData: It is to be had for the modern request handiest and requires typecasting for complex facts type.

ViewBag: Dynamic property that takes gain of the brand new dynamic features in C# 4.0, additionally available for the current request handiest. If redirection happens, then its fee turns into null and doesn’t require typecasting for complicated facts type.

TempData: used to bypass facts from the modern-day request to the next request, continues the data for the period of an HTTP Request. This method best from one page to every other.

Q12. Explain the MVC software lifestyles cycle.

Ans: Any web utility first knows the request and relying on type of request, it sends out suitable response. MVC software existence cycle isn't distinctive, it has two essential levels, first developing the request object and 2d sending our response to the browser.

The request object creation has four predominant steps,

Step 1: Fill route

Every MVC request is mapped to direction table which specifies which controller and action to be invoked. If it's miles the primary request, it fills the direction table with route series. This filling of direction desk occurs within the worldwide.Asaxfile.

Step 2: Fetch route

Depending at the URL despatched "UrlRoutingModule" searches the route desk to create "RouteData" object. RouteData has the information of which controller and action to invoke.

Step 3: Request context created

The "RouteData" object is used to create the "RequestContext" object.

Step 4: Controller instance created

The coming request object is sent to "MvcHandler" instance to create the item of controller class. Once the controller magnificence item is created, it calls the "Execute" technique of the controller class.

Creating Response item:

This segment has  steps - Executing the motion and ultimately sending the reaction as a end result to the view.

Q13. What are HTML Helpers and why to use it?

Ans: HtmlHelper elegance generates html elements the usage of the version magnificence item in razor view. It binds the version item to html elements to show cost of version houses into html elements and additionally assigns the fee of the html elements to the model properties while submitting internet shape. So constantly use HtmlHelper class in razor view as opposed to writing html tags manually.

Q14. What do you realize approximately bundling and minification in MVC?

Ans: In MVC, bundling and minification facilitates us enhance request load instances of a page. It will increase the overall performance of the packages.

Q15. What is RESTfull APIs?

Ans: REST stands for REpresentational State Transfer. REST is net requirements based architecture and makes use of HTTP Protocol for information communique. It revolves round aid in which each element is a resource and a aid is accessed by way of a commonplace interface using HTTP preferred techniques

In REST structure, a REST Server genuinely gives get right of entry to to resources and REST purchaser accesses and presents the assets. Here each aid is recognized by using URIs/ worldwide IDs. REST makes use of diverse representations to represent a useful resource like textual content, JSON and XML. Now a days JSON is the most famous layout being utilized in internet offerings.

Q16. What is the modern day model of MVC?

Ans: When this notice became written, four versions in which launched of MVC. MVC 1 , MVC 2, MVC 3 and MVC four. So the modern day isMVC 4

Q17. What is Output Caching in MVC?

Ans: It enables us to cache the content back by any controller approach so that the identical content material does not need to be generated each time the same controller technique is invoked. Output Caching has huge advantages, such because it reduces server spherical journeys, reduces database server round journeys, reduces community visitors etc. The primary motive of the usage of Output Caching is to enhance the overall performance of the software.

Q18. What is the difference among each model of MVC?

Ans: Below is a element table of differences. But for the duration of interviewit’s tough to speak about all of them due to timelimitation.So I even have highlighted critical variations which you may run through earlier than the interviewer.


MVC three


Client-Side Validation TemplatedHelpers Areas AsynchronousControllers

Html.ValidationSummaryHelper Method DefaultValueAttribute inActionMethod Parameters Binding BinaryData with Model Binders DataAnnotationsAttributes Model-Validator Providers NewRequireHttpsAttribute Action FilterTemplated Helpers Display Model-LevelErrors


Readymade undertaking templates

HTML 5 enabled templatesSupportfor Multiple View EnginesJavaScriptand Ajax

Model Validation Improvements


Refreshed and modernized defaultproject templatesNew cell projecttemplate

Many new functions to help mobileapps

Enhanced support for asynchronousmethods

Q19. What is Bundling and Minification in MVC?

Ans: Bundling and minification are  strategies you may use to improve request load time.

Bundling lets you download files of identical type the usage of one request in preference to more than one requests. This manner you can down load patterns and scripts the use of less requests than it takes to request all files separately.

Minification plays an expansion of various code optimizations to scripts or css, such as getting rid of useless white area,comments and shortening variable names to one person.

Q20. What is minification and the way to enforce minification in MVC?

Ans: Minification is a process to remove the clean space, comments and many others.

The implementation of minification is as like as bundling. That method when we put in force bundling minification is also implemented routinely. A sample JavaScript codes with feedback:

// This is check remarks

var x = 5;

x = x + 2;

x = x * 3;

After imposing minification the JavaScript code seems like:

var x=five;x=x+12x=x*3

Q21. What is Partial View in MVC?

Ans: A partial view is a component constructed by the developer to re-use a bulk of HTML that may be inserted into an current DOM. Most normally, partial views are used to componentize Razor views and cause them to less difficult to build and replace. Partial perspectives can also be again at once from controller methods.

Q22. What about static documents in ASP.NET Core (MVC)?

Ans: All static files are actually (by using default) located inside of wwwrootfolder. You shop your CSS, JS, pics, fonts and others static content internal of it.