ASP.NET MVC Interview Questions and Answers (162) - Page 8

What is Strongly Typed HTML Helpers?

These kind of Html Helpers comes into use when the HTML elements are created based on model properties in a strongly types view. What the statement means can be better demonstrated by an example -

Let us create a model say Employee

namespace DemoModel

{
public class Employee
{
public int EmpID { get; set; }
public string EmpName { get; set; }
}
}


Now let us create a strongly typed Employee using the Html helpers as under

@model DemoModel.Employee

@using(@Html.BeginForm()){

<div>
@Html.DisplayFor(m => m.EmpID)
@Html.TextBoxFor(m=>m.EmpID)
</div>

<div>
@Html.DisplayFor(m => m.EmpName)
@Html.TextBoxFor(m=>m.EmpName)
</div>
}


From the above code snippet, it is clear that the strongly typed HTML helpers work on lambda expression where the model object is passed as a value to lambda expression and we can select the field or property from model object to be used to set the id, name and value attributes of the HTML helper. The above code snippet will be render to

<div>

<span id="EmpID" name="EmpID"> { EmpID value(s) }</span>
<input id="EmpID" name="EmpID" type="text" value="{ EmpID value(s) }" />
</div>
<div>
<span id="EmpName" name="EmpName"> { EmpName value(s) }</span>
<input id="EmpName" name="EmpName" type="text" value="{ EmpName value(s) }" />
</div>

What is UnTyped Typed HTML Helper?

UnTyped Typed HTML Helpers are those HTML Helpers that are not bound to any Model data.

E.g. @Html.RadioButton("myRDBtn", "val", true) 


This will be render to

<input type="radio" id="myRDBtn" name="myRDBtn" checked="checked" value="val" />


This radio button is not tied to any model and hence become an UnTyped Typed HTML Helper.
Under which situation we will go for ASP.net MVC project?

NOTE: This is objective type question, Please click question title for correct answer.
Why we need to prefer MVC over Webforms?

Most of them all well versed with Webforms in ASP.net but MVC will make so many lives easy with its approach lets see the reasons

1) The page life cycle is much more simpler and efficient.

2) It is very light weight and there is no CodeBehind concept here.

3) It also gives us the complete control over the HTML that was rendered.

4) No Viewstate is being loaded is a major Performance booster.

5) Integration will be easy with respect to multiple Client side scripting technologies

6) As each layer is independent of other the Implementation among different bunch of developers becomes easy.
What is the role of Database Intializer for Code First approach in Entity Framework?

The main role of Database Intializer is to create the Database and the specified tables. When we use DBContext type to use the database for the very first time then Database Intializer will be called.

Creating New Database
Generally Database.SetInitializer() is the Initialization approach. This method will take the parameter of IDatabaseInitializer<TContext> where the TContext will be of DbContextType.

IDatabaseInitializer<TContext> has 3 implementations namely:
1) CreateDatabaseIfNotExists<TContext> (Creates a new Database)
2) DropCreateDatabaseAlways<TContext> (It Drops and Recreates database all the time)
3) DropCreateDatabaseIfModelChanges<TContext>(It Drops and Recreates only when there are some modifications to the Model)

Using Existing Database

If we want to use the existing database then we need to set the Database intializer with null so that we can modify the already existing database.
Database.SetInitializer<PortalContext>(null);
Which of the following is the Segment which is important routing in MVC?

NOTE: This is objective type question, Please click question title for correct answer.
Can we implement Ajax using Jquery in MVC?

NOTE: This is objective type question, Please click question title for correct answer.
What are Scaffold templates in MVC?

Generally the term scaffold means a temporary platform that was set to build some thing.

For Example: Painters put some temporary arrangements with wood to paint the outside part of a building.

So as the term suggests these scaffold templates are used to generate code for the basic CRUD operations within our ASP.NET MVC application against our database with the help of entity framework.

Steps followed to create a scaffold template are:

Step1: we need to add a controller to our project first.
Step2: Choose the respective Scaffold template to perform CRUD operations
(Ex: In AddScaffold pop up add MVC5 controller with Read/Write actions)
Step3: Giving a decent name to our controller.

So now it generates the code for insert,update and delete operations
How can we add a CSS file in Razor View?

Below is the sample code to add a css file which is already located in the application folder:

<link rel="StyleSheet" href="/@Href(~Content/Style.css")" type="text/css"/>


This shows that Style.css file is in Content folder.
What is Dependency Injection and how it is useful in MVC?

The Dependency Injection is just like a Design pattern which is predominantly used for developing loosely coupled code.

Below are the different advantages that we get using DI

1) It improves code Maintainability
2) It improves code Re-Usability
3) It improves code Coupling
4) It improves application level testing too.
What does MVC stands for ?

NOTE: This is objective type question, Please click question title for correct answer.
What is the functionality of Model in Asp.net MVC?

NOTE: This is objective type question, Please click question title for correct answer.
What is a View in Asp.net MVC?

NOTE: This is objective type question, Please click question title for correct answer.
What is controller in Asp.net MVC?

NOTE: This is objective type question, Please click question title for correct answer.
Identify the correct statement(s)?

NOTE: This is objective type question, Please click question title for correct answer.
Identity the correct statement(s) about Action Methods of Controller in MVC

NOTE: This is objective type question, Please click question title for correct answer.
What is the default Action Method when an MVC project gets created?

NOTE: This is objective type question, Please click question title for correct answer.
Which is the base class for all the result type which returns from Action method?

NOTE: This is objective type question, Please click question title for correct answer.
In an ASP .Net MVC Application, browsers requests are mapped to?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories