MVC Developer

  Home  Computer Programming  MVC Developer


“MVC Developer based Frequently Asked Questions in various MVC Developer job interviews by interviewer. These professional questions are here to ensures that you offer a perfect answers posed to you. So get preparation for your new job hunting”



50 MVC Developer Questions And Answers

21⟩ What is the concept of MVC Scaffolding?

ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.

Scaffolding consists of page templates, entity page templates, field page templates, and filter templates. These templates are called Scaffold templates and allow you to quickly build a functional data-driven Website.

Scaffolding Templates:

☛ Create: It creates a View that helps in creating a new record for the Model. It automatically generates a label and input field for each property in the Model.

☛ Delete: It creates a list of records from the model collection along with the delete link with delete record.

☛ Details: It generates a view that displays the label and an input field of the each property of the Model in the MVC framework.

☛ Edit: It creates a View with a form that helps in editing the current Model. It also generates a form with label and field for each property of the model.

☛ List: It generally creates a View with the help of a HTML table that lists the Models from the Model Collection. It also generates a HTML table column for each property of the Model.

 148 views

22⟩ Tell me a few different return types of a controller action method?

The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.

☛ 1. ViewResult

☛ 2. JavaScriptResult

☛ 3. RedirectResult

☛ 4. ContentResult

☛ 5. JsonResult

 135 views

23⟩ What is RenderSection in MVC?

RenderSection() is a method of the WebPageBase class. Scott wrote at one point, The first parameter to the "RenderSection()" helper method specifies the name of the section we want to render at that location in the layout template. The second parameter is optional, and allows us to define whether the section we are rendering is required or not. If a section is "required", then Razor will throw an error at runtime if that section is not implemented within a view template that is based on the layout file (that can make it easier to track down content errors). It returns the HTML content to render.

<div id="body">

@RenderSection("featured", required: false)

<section class="content-wrapper main-content clear-fix">

@RenderBody()

</section>

</div>

 120 views

24⟩ Tell me how can we do exception handling in MVC?

In the controller you can override the “OnException” event and set the “Result” to the view name which you want to invoke when error occurs. In the below code you can see we have set the “Result” to a view named as “Error”.

We have also set the exception so that it can be displayed inside the view.

public class HomeController : Controller

{

protected override void OnException(ExceptionContext filterContext)

{

Exception ex = filterContext.Exception;

filterContext.ExceptionHandled = true;

var model = new HandleErrorInfo(filterContext.Exception, "Controller","Action");

filterContext.Result = new ViewResult()

{

ViewName = "Error",

ViewData = new ViewDataDictionary(model)

};

}

}

To display the above error in view we can use the below code

@Model.Exception;

 136 views

25⟩ Tell us what are the advantages of ASP.NET MVC?

☛ 1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.

☛ 2. Complex applications can be easily managed

☛ 3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller.

☛ 4. ASP.NET MVC views are light weight, as they donot use viewstate.

 139 views

26⟩ Tell us what is ViewStart?

Razor View Engine introduced a new layout named _ViewStart which is applied on all view automatically. Razor View Engine firstly executes the _ViewStart and then start rendering the other view and merges them.

Example of Viewstart:

@ {

Layout = "~/Views/Shared/_v1.cshtml";

} < !DOCTYPE html >

< html >

< head >

< meta name = "viewport"

content = "width=device-width" / >

< title > ViewStart < /title> < /head> < body >

< /body> < /html>

 133 views

27⟩ Explain me what is the difference between ActionResult and ViewResult?

ActionResult is an abstract class while ViewResult derives from the ActionResult class.

ActionResult has several derived classes like ViewResult, JsonResult, FileStreamResult, and so on.

ActionResult can be used to exploit polymorphism and dynamism. So if you are returning different types of views dynamically, ActionResult is the best thing. For example in the below code snippet, you can see we have a simple action called DynamicView. Depending on the flag (IsHtmlView) it will either return a ViewResult or JsonResult.

☰ public ActionResult DynamicView()

☰ {

☰ if (IsHtmlView)

☰ return View(); // returns simple ViewResult

☰ else

☰ return Json(); // returns JsonResult view

☰ }

 141 views

28⟩ Tell me different return types of a controller action method?

There are total nine return types we can use to return results from controller to view.

☛ ViewResult (View): This return type is used to return a webpage from an action method.

☛ PartialviewResult (Partialview): This return type is used to send a part of a view which will be rendered in another view.

☛ RedirectResult (Redirect): This return type is used to redirect to any other controller and action method depending on the URL.

☛ RedirectToRouteResult (RedirectToAction, RedirectToRoute): This return type is used when we want to redirect to any other action method.

☛ ContentResult (Content): This return type is used to return HTTP content type like text/plain as the result of the action.

☛ jsonResult (json): This return type is used when we want to return a JSON message.

☛ javascriptResult (javascript): This return type is used to return JavaScript code that will run in browser.

☛ FileResult (File): This return type is used to send binary output in response.

☛ EmptyResult: This return type is used to return nothing (void) in the result.

 145 views

29⟩ Do you know what is the difference between View and Partial View?

View:

☛ It contains the layout page.

☛ Before any view is rendered, viewstart page is rendered.

☛ View might have markup tags like body, html, head, title, meta etc.

☛ 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 viewstart.cshtml.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 RenderPartial method.

 165 views

30⟩ Please explain what does Model, View and Controller represent in an MVC application?

Model: Model represents the application data domain. In short the applications business logic is contained with in the model.

View: Views represent the user interface, with which the end users interact. In short the all the user interface logic is contained with in the UI.

Controller: Controller is the component that responds to user actions. Based on the user actions, the respective controller, work with the model, and selects a view to render that displays the user interface. The user input logic is contained with in the controller.

 165 views

31⟩ Tell us what is Output Caching in MVC?

The main purpose of using Output Caching is to dramatically improve the performance of an ASP.NET MVC Application. It enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked. Output Caching has huge advantages, such as it reduces server round trips, reduces database server round trips, reduces network traffic etc.

OutputCache label has a "Location" attribute and it is fully controllable. Its default value is "Any", however there are the following locations available; as of now, we can use any one.

☛ Any

☛ Client

☛ Downstream

☛ Server

☛ None

☛ ServerAndClient

 135 views

32⟩ Explain me the meaning of Unobtrusive JavaScript?

This is a general term that conveys a general philosophy, similar to the term REST (Representational State Transfer). Unobtrusive JavaScript doesn't intermix JavaScript code in your page markup.

Eg : Instead of using events like onclick and onsubmit, the unobtrusive JavaScript attaches to elements by their ID or class based on the HTML5 data- attributes.

 136 views

35⟩ Explain me what is Validation Summary in MVC?

The ValidationSummary helper method generates an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.

The ValidationSummary can be used to display all the error messages for all the fields. It can also be used to display custom error messages. The following figure shows how ValidationSummary displays the error messages.

 147 views

36⟩ Tell us what are the advantages of MVC?

☛ A main advantage of MVC is separation of concern. Separation of concern means we divide the application Model, Control and View.

☛ We can easily maintain our application because of separation of concern.

☛ In the same time we can split many developers work at a time. It will not affects one developer work to another developer work.

☛ It supports TTD (test-driven development). We can create an application with unit test. We can write won test case.

☛ Latest version of MVC Support default responsive web site and mobile templates.

 152 views

37⟩ Tell us what is GET and POST Actions Types?

GET

GET is used to request data from a specified resource. With all the GET request we pass the URL which is compulsory, however it can take the following overloads.

.get(url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] ).done/.fail

POST

POST is used to submit data to be processed to a specified resource. With all the POST requests we pass the URL which is compulsory and the data, however it can take the following overloads.

.post(url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

 174 views

40⟩ What is Dependency Resolution?

Dependency Resolver again has been introduced in MVC3 and it is greatly simplified the use of dependency injection in your applications. This turn to be easier and useful for decoupling the application components and making them easier to test and more configurable.

 152 views