October 11, 2018

Sreekanth B

Cognizant ASP.NET MVC Recent Interview Questions Answers

Cognizant ASP.NET MVC Recent Most common Interview Questions And Answers 2018

What is the difference between each version of MVC 2, 3 , 4, 5 and 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.


Asp.Net Identity

Attribute based routing

Bootstrap in the MVC template

Filter overrides

Authentication Filters



New mobile project template

Refreshed and modernized default project templates

Many new features to support mobile apps



HTML 5 enabled templates

JavaScript and Ajax

Support for Multiple View Engines

Model Validation Improvements


Templated Helpers

Client-Side Validation


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

What are HTML helpers in MVC?

HTML helpers help you to render HTML controls in the view. For instance if you want to display a HTML textbox on the view , below is the HTML helper code.

<%= Html.TextBox("FirstName") %>

For checkbox below is the HTML helper code. In this way we have HTML helper methods for every HTML control that exists.

<%= Html.CheckBox("Yes") %>

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”.

Where is the route mapping code written?

The route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.

What is Razor in MVC?  
Razor is not a new programming language itself, but uses C# syntax for embedding code in a page without the ASP.NET delimiters: <%= %>. It is a simple-syntax view engine and was released as part of ASP.NET MVC 3. The Razor file extension is "cshtml" for the C# language. It supports TDD (Test Driven Development) because it does not depend on the System.Web.UI.Page class.

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

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


     return Json(); // returns JsonResult view


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.


What Are The Components Required To Create A Route In Asp.net Mvc?

Name - This is the name of the route.

URL Pattern : Placeholders will be given to match the request URL pattern.

Defaults :When loading the application which controller, action to be loaded along with the parameter.

Why To Use "{resource}.axd/{*pathinfo}" In Routing In Asp.net Mvc?

Using this default route - {resource}.axd/{*pathInfo}, we can prevent the requests for the web resources files like - WebResource.axd or ScriptResource.axd from passing to a controller.

Can We Add Constraints To The Route? If Yes, Explain How We Can Do It?

Yes we can add constraints to route in following ways :

Using Regular Expressions

Using object which implements interface - IRouteConstraint.

Subscribe to get more Posts :