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

2⟩ Explain me what is the difference between each version of MVC 2, 3 , 4, 5 and 6?

MVC 6

☛ ASP.NET MVC and Web API has been merged in to one.

☛ Side by side - deploy the runtime and framework with your application

☛ No need to recompile for every change. Just hit save and refresh the browser.

☛ Dependency injection is inbuilt and part of MVC.

☛ Everything packaged with NuGet, Including the .NET runtime itself.

☛ New JSON based project structure.

☛ Compilation done with the new Roslyn real-time compiler.

MVC 5

☛ Asp.Net Identity

☛ Attribute based routing

☛ Bootstrap in the MVC template

☛ Filter overrides

☛ Authentication Filters

MVC 4

☛ ASP.NET Web API

☛ New mobile project template

Refreshed and modernized default project templates

Many new features to support mobile apps

MVC 3

☛ Razor

☛ HTML 5 enabled templates

☛ JavaScript and Ajax

☛ Support for Multiple View Engines

☛ Model Validation Improvements

MVC 2

☛ Templated Helpers

☛ Client-Side Validation

☛ Areas

☛ Asynchronous Controllers

☛ Html.ValidationSummary Helper Method

☛ DefaultValueAttribute in Action-Method Parameters

☛ Binding Binary Data with Model Binders

☛ DataAnnotations Attributes

☛ Model-Validator Providers

☛ New RequireHttpsAttribute Action Filter

 209 views

3⟩ Tell me what is MVC (Model View Controller)?

MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller. Below is how each one of them handles the task.

☛ The View is responsible for the look and feel.

☛ Model represents the real world object and provides data to the View.

☛ The Controller is responsible for taking the end user request and loading the appropriate Model and View

 147 views

4⟩ Tell me what is the adavantage of using ASP.NET routing?

In an ASP.NET web application that does not make use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error.

An ASP.NET web application that does make use of routing, makes use of URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.

 149 views

7⟩ Tell me how to implement Forms authentication in MVC?

ASP.NET forms authentication occurs after IIS authentication is completed. You can configure forms authentication by using forms element with in web.config file of your application. The default attribute values for forms authentication are shown below:

☰ <system.web>

☰ <authenticationmode="Forms">

☰ <formsloginUrl="Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" />

☰ </authentication>

☰ </system.web>

The FormsAuthentication class creates the authentication cookie automatically when SetAuthCookie() or RedirectFromLoginPage() methods are called. The value of authentication cookie contains a string representation of the encrypted and signed FormsAuthenticationTicket object.

 153 views

8⟩ Tell us what is display mode in MVC?

Display mode displays views depending on the device the user has logged in with. So we can create different views for different devices and display mode will handle the rest.

For example we can create a view “Home.aspx” which will render for the desktop computers and Home.Mobile.aspx for mobile devices. Now when an end user sends a request to the MVC application, display mode checks the “user agent” headers and renders the appropriate view to the device accordingly.

 156 views

10⟩ Tell us 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 = "Hasan";

Calling of ViewData is :

ViewData["Name"] = " Hasan ";

 154 views

11⟩ Tell us attribute based routing in MVC?

In ASP.NET MVC 5.0 we have a new attribute route, By using the "Route" attribute we can define the URL structure. For example in the below code we have decorated the "GotoAbout" action with the route attribute. The route attribute says that the "GotoAbout" can be invoked using the URL structure "Users/about".

☰ public class HomeController: Controller

☰ {

☰ [Route("Users/about")]

☰ publicActionResultGotoAbout()

☰ {

☰ return View();

☰ }

☰ }

 163 views

12⟩ Explain me 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();

 162 views

13⟩ Explain what are Filters in MVC?

In MVC, many times we would like to perform some action before or after a particular operation. For achieving this functionality, ASP.NET MVC provides feature to add pre and post action behaviors on controller's action methods.

Types of Filters:

ASP.NET MVC framework supports the following action filters:

☛ Action Filters: Action filters are used to implement logic that gets executed before and after a controller action executes.

☛ Authorization Filters: Authorization filters are used to implement authentication and authorization for controller actions.

☛ Result Filters: Result filters contain logic that is executed before and after a view result is executed. For example, you might want to modify a view result right before the view is rendered to the browser.

☛ Exception Filters: You can use an exception filter to handle errors raised by either your controller actions or controller action results. You can also use exception filters to log errors.

 167 views

15⟩ What is Bundle.Config in MVC4?

"BundleConfig.cs" in MVC4 is used to register the bundles by the bundling and minification system. Many bundles are added by default including jQuery libraries like - jquery.validate, Modernizr, and default CSS references.

 156 views

16⟩ Tell us 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 Boos!");

}

 148 views

17⟩ Tell us what is the significance of NonActionAttribute?

ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods. ASP.NET Routing makes use of route table. Route table is created when your web application first starts. The route table is present in the Global.asax file.

 154 views

18⟩ Explain me what is MVC Application Life Cycle?

Any web application has two main execution steps first understanding the request and depending on the type of the request sending out the appropriate response. MVC application life cycle is not different it has two main phases first creating the request object and second sending our response to the browser.

Creating the request object: -The request object creation has four major steps. Below is the detail explanation.

☛ Step 1 Fill route: MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the route table with routes collection. This filling of route table happens in the global.asax file.

☛ Step 2 Fetch route: Depending on the URL sent “UrlRoutingModule” searches the route table to create “RouteData” object which has the details 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: This request object is sent to “MvcHandler” instance to create the controller class instance. Once the controller class object is created it calls the “Execute” method of the controller class.

☛ Step 5 Creating Response object: This phase has two steps executing the action and finally sending the response as a result to the view.

 176 views

19⟩ Explain me what is the difference between “HTML.TextBox” and “HTML.TextBoxFor”?

Both provide the same HTML output, “HTML.TextBoxFor” is strongly typed while “HTML.TextBox” isn’t. Below is a simple HTML code which just creates a simple textbox with “FirstName” as name.

Html.TextBox("FirstName ")

Below is “Html.TextBoxFor” code which creates HTML textbox using the property name ‘FirstName” from object “m”.

Html.TextBoxFor(m => m.CustomerCode)

In the same way, we have for other HTML controls like for checkbox we have “Html.CheckBox” and “Html.CheckBoxFor”.

 160 views

20⟩ Explain me what is the difference between Temp data, View, and View Bag?

In ASP.NET MVC there are three ways to pass/store data between the controllers and views.

ViewData

☛ ViewData is used to pass data from controller to view.

☛ It is derived from ViewDataDictionary class.

☛ It is available for the current request only.

☛ Requires typecasting for complex data type and checks for null values to avoid error.

☛ If redirection occurs, then its value becomes null.

ViewBag

☛ ViewBag is also used to pass data from the controller to the respective view.

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

☛ It is also available for the current request only.

☛ If redirection occurs, then its value becomes null.

☛ Doesn’t require typecasting for complex data type.

TempData

☛ TempData is derived from TempDataDictionary class

☛ TempData is used to pass data from the current request to the next request

☛ It keeps the information for the time of an HTTP Request. This means only from one page to another. It helps to maintain the data when we move from one controller to another controller or from one action to another action

☛ It requires typecasting for complex data type and checks for null values to avoid error. Generally, it is used to store only one time messages like the error messages and validation messages

 190 views