HCL Technologies ASP.NET MVC Recent Interview Questions Answers

HCL Technologies ASP.NET MVC Recent Most common Interview Questions And Answers 

What is the use of Keep and Peek in “TempData”?

Once “TempData” is read in the current request it’s not available in the subsequent request. If we want “TempData” to be read and also available in the subsequent request then after reading we need to call “Keep” method as shown in the code below.

@TempData["MyData"];

TempData.Keep("MyData");

 The more shortcut way of achieving the same is by using “Peek”. This function helps to read as well advices MVC to maintain “TempData” for the subsequent request.

string str = TempData.Peek("MyData ").ToString();

What is Bundling and Minification in MVC?

Bundling and minification are two new techniques introduced to improve request load time. It improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript).

Bundling: It lets us combine multiple JavaScript (.js) files or multiple cascading style sheet (.css) files so that they can be downloaded as a unit, rather than making individual HTTP requests.

Minification: It squeezes out whitespace and performs other types of compression to make the downloaded files as small as possible. At runtime, the process identifies the user agent, for example IE, Mozilla, etc. and then removes whatever is specific to Mozilla when the request comes from IE.

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.
HCL Technologies ASP.NET MVC Recent Interview Questions Answers
HCL Technologies ASP.NET MVC Recent Interview Questions Answers

What are the Folders in MVC application solutions?

When you create a project a folder structure gets created by default under the name of your project which can be seen in solution explorer. Below I will give you a brief explanation of what these folders are for.

Model: This folder contains classes that is used to provide data. These classes can contain data that is retrieved from the database or data inserted in the form by the user to update the database.

Controllers: These are the classes which will perform the action invoked by the user. These classes contains methods known as "Actions" which responds to the user action accordingly.

Views: These are simple pages which uses the model class data to populate the HTML controls and renders it to the client browser.

App_Start: Contains Classes such as FilterConfig, RoutesConfig, WebApiConfig. As of now we need to understand the RouteConfig class. This class contains the default format of the URL that should be supplied in the browser to navigate to a specified page.

If we have multiple filters, what’s the sequence for execution?

Authorization filters
Action filters
Response filters
Exception filters

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>

What is JsonResultType in MVC?

Action methods on controllers return JsonResult (JavaScript Object Notation result) that can be used in an AJAX application. This class is inherited from the "ActionResult" abstract class. Here Json is provided one argument which must be serializable. The JSON result object that serializes the specified object to JSON format.

public JsonResult JsonResultTest()

{

    return Json("Hello My Friend!");

}

What are the Difference between ViewBag&ViewData?

ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys.

ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.

ViewData requires typecasting for complex data type and check for null values to avoid error.

ViewBag doesn't require typecasting for complex data type.

Calling of ViewBag is:

ViewBag.Name = "Vikash";

Calling of ViewData is :

ViewData["Name"] = " Vikash ";

Explain 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>

How To Change The Action Name In Asp.net Mvc?

"ActionName" attribute can be used for changing the action name.

Below is the sample code snippet to demonstrate more :

[ActionName("TestActionNew")]

public ActionResult TestAction()

    {

       return View();

    }

So in the above code snippet "TestAction" is the original action name and in "ActionName" attribute, name - "TestActionNew" is given. So the caller of this action method will use the name "TestActionNew" to call this action.

What Are Code Blocks In Views?

Unlike code expressions that are evaluated and sent to the response, it is the blocks of code that are executed. This is useful for declaring variables which we may be required to be used later.

@{

 int x = 123;

 string y = "aa";

 }

What Is The "helper Page.isajax" Property?

The Helper Page.IsAjax property gets a value that indicates whether Ajax is being used during the request of the Web page.

How We Can Call A Javascript Function On The Change Of A Dropdown List In Asp.net Mvc?

Create a JavaScript method:

function DrpIndexChanged() { } Invoke the method:

< %:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Customers, "Value", "Text"), "Please Select a Customer", new { id = "ddlCustomers", onchange=" DrpIndexChanged ()" })%>


Post a Comment

Previous Post Next Post