InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is a postback? |
|
Answer» A postback will occur when clients MAKE a request for a server response from their viewing page. Consider a simple example of a form completion by the user and hitting the “submit” button. In this case, the property IsPostBack will be TRUE, so the request will be processed by the server and a response will be sent back to the client. A postback helps to REFRESH the entire page when a data retrieval request has been MADE with a callback WITHOUT completely refreshing the page. |
|
| 2. |
Explain different development approaches with the Entity framework. |
|
Answer» Three different development approaches will be provided by the Entity framework while dealing with the database and data access layer in the application according to the NEED of the project. They are: Database-First APPROACH: This approach will be used if there is an already existing database schema. Here, context and entities will be generated for the existing database using the EDM(Entity Data Model) wizard. This approach is considered to be the best for applications that will make USE of an already existing database. The Database-First approach is useful in the following cases:
Code-First Approach: This approach is used when the existing database is not present for your application. In this approach, you will write the entities(domain classes) and context classes, then the database will be created from these classes with the help of migration commands. This approach is considered to be the best for highly domain-centric applications and that will create the domain model classes in the beginning. Here, the database will be required only as a persistence mechanism for these newly created domain models. That implies, if a developer is following the principles of Domain-Driven Design(DDD), they will start the coding with the creation of domain classes and then the database required will be generated for persisting their data. The Code First approach is useful in the following situations:
Model-First Approach: In this approach, the entities, inheritance hierarchies, and relationships will be created directly on the visual DESIGNER and then can generate context class, database script, and entities using the visual model. The Model-First approach is useful in the situation:
|
|
| 3. |
What is the purpose of ”beforeRender()”, “beforeFilter()”, and “afterFilter()” functions in Controller? |
Answer»
|
|
| 4. |
Discuss a few necessary namespaces used in ASP.NET MVC. |
|
Answer» Few significant namespaces that are used in ASP.NET MVC applications are:
|
|
| 5. |
How to use multiple models to a single view in ASP.NET MVC? |
|
Answer» ASP.NET MVC will PERMIT only a single model to be bound to each view, but there are many workarounds for this. For example, the class ExpandoObject in the ASP.NET framework is a dynamic model which will be passed to a view. Another common solution is the usage of ViewModel class(a class with SEVERAL models), ViewBag(a property of the ControllerBase class which is dynamic), or ViewData(a dictionary object). It is also possible to use Tuple, JSON, and RenderAction. In the example given below, you can get to know about how to use multiple models in a single view with the help of the ViewModel class. Here, ViewModel has two properties namely Managers and Employees that acts as a model. ViewModel class: public class ViewModel{ public IEnumerable<Manager> Managers { get; set; } public IEnumerable<Employee> Employees { get; set; }}Controller CODE: public ActionResult IndexViewModel(){ ViewBag.Message = "Welcome to my example program!"; ViewModel demomodel = new ViewModel(); demomodel.Managers = GetManagers(); demomodel.Employees = GetEmployees(); return View(demomodel);}View code: @using MultipleModelInOneView;@model ViewModel@{ ViewBag.Title = "Home PAGE";}<h2>@ViewBag.Message</h2><p><b>Manager List</b></p><table> <tr> <th>ManagerId</th> <th>Department</th> <th>Name</th> </tr> @foreach (Manager manager in Model.Managers) { <tr> <td>@manager.ManagerId</td> <td>@manager.Department</td> <td>@manager.Name</td> </tr> }</table><p><b>Employee List</b></p><table> <tr> <th>EMPLOYEEID</th> <th>Name</th> <th>Designation</th> </tr> @foreach (Employee employee in Model.Employees) { <tr> <td>@employee.EmployeeId</td> <td>@employee.Name</td> <td>@employee.Designation</td> </tr> }</table> |
|
| 6. |
What is a glimpse in ASP.NET MVC? |
|
Answer» Glimpse is a WEB debugging and diagnostics TOOL that can be used with your ASP.NET or ASP.NET MVC applications for finding the information related to performance, debugging, and diagnostic. It helps you to obtain information regarding model BINDING, timelines, environment, routes, ETC. It is possible to integrate Glimpse with insights into an application. An intuitive user interface will be provided by Glimpse for examining the performance data of an application. Glimpse adds a widget to the web pages for VIEWING the performance-related data as you browse through the application web pages. |
|
| 7. |
What is the use of Validation Summary? |
Answer»
For example, the below-given code will display a heading “Please fix the problem:” for a list of all the String.Empty messages. @Html.ValidationSummary(True, "Please fix the problem:") |
|
| 8. |
What are HTML Helper methods? |
|
Answer» Helper methods are useful in rendering the HTML in the view. These methods will GENERATE an HTML output as a part of the view. They need less coding as it can be reused across the views, so it is advantageous over HTML ELEMENTS. The different built-in helper methods are available that can be used for GENERATING the HTML for a few most commonly used HTML elements such as dropdown list, FORM, checkbox, etc. Along with this, it is also possible to create our own helper methods for custom HTML generation. A few STANDARD helper methods in MVC are given-below:
|
|
| 9. |
Explain RenderSection() in detail. |
|
Answer» The RenderSection() method belongs to the WebPageBase class and is used for rendering the content of the defined section. The RenderSection() method’s FIRST parameter will be the section name we wish to render at that particular location in the layout template. The second parameter will enable us for defining whether the rendering section is needed or not and this parameter is OPTIONAL. If it is a “required” section, then an error will be thrown by the Razor if that section has not been implemented WITHIN a view template. It returns the HTML content for rendering purposes. For EXAMPLE, a section named “note” in a layout page can be defined as follows: @section note{<h1>Header Content</h1>}The above-defined section can be rendered on the content page by using the below code: @RenderSection("note") All sections are compulsory by default. To make the sections optional, you need to provide the value of the second parameter as a boolean value false. <div id="body"> @RenderSection("note", false) //used for injecting the content in the defined section <section class="content-wrapper main-content clear-fix"> @RenderBody() </section></div>Using the above code, the section named “note” will be rendered on the content page. Here, the RenderBody method can be used for rendering the child page/view. |
|
| 10. |
Explain about ASP.NET MVC life cycle. |
|
Answer» A Life cycle refers to a sequence of events or steps used for handling some kind of request or modifying the state of an application. ASP.NET MVC has two life cycles. They are:
The route data will be converted by the MVC framework into a concrete controller that is capable of handling the requests. The major task after the creation of a controller is Action Execution. An action invoker component will find and select the suitable Action method for invoking the controller. The next stage after the PREPARATION of the action result is Result Execution. MVC will separate result DECLARATION from result execution. If the result is of view, then it will find and render our view by CALLING the View Engine. If the result is not a view type, the action result will be executed on its own. This Result Execution will generate an original response to the actual HTTP request. |
|