MVC Interview Questions and Answers - Page 1

What are Razor engines? How is it different from ASP Engines

RAZOR engine is the
new concept in the MVC 3 which is mainly used to create the views in the MVC
applications. It created the cshtml pages for the MVC application and cshtml
pages can be generated automatically by using the Razor engine.ASP engine
create the aspx pages while Razor engine creates the pages.

What is MVC?

MVC (Model View Controller) is one of the Software Architectural pattern which is built on 3 layers. So it is the pattern which basically talks about the separation of concern for a project. Here the 3 parts are having their own roles like:

  • Model - It is used as the Data Container or it can also have the business rules, functions, logic's etc.
  • View - It is mainly the UI (User Interface) part which is the main application built using the Web technologies like ASP.Net etc. It consists of the User Interface Design, representation of the information for the end users etc.
  • Controller - It is the mediator between the View and Model and used to control the requests and responses floating through the views and Model. The command, Actions, Events are the part of Controller in MVC. All the communication is done via Controller so we can say that Controller is the heart of MVC.

life cycle of mvc

The application life cycle of MVC includes the request, processing, filtering and execution and then finally the response back to the requester. The request first goes to URL routing module(HTTP Module) and there it gets decided that whether this is MVC request and will be handled or not. Now if the request is for MVC application, the URL routing module selects the first route which is satisfying the requested URL. As soon as the first match found for the requested URL, the process for the execution begins with the Controller and Model(if any) and the response sends back to the browser.

advantages of MVC framework

The following are the advantages of MVC framework:

  1. Separation of Concerns
  2. Light weight
  3. No round trip for the layers
  4. Decoupling between the layers
  5. No dependencies between the Model, View and Controller 

What are the difference between asynchronous controller implementation between ASP.NET MVC 3 and ASP.NET MVC 4?

There is major difference is on implementation mechanism between ASP.NET MVC 3 and ASP.NET MVC 4.

In ASP.NET MVC 3, to implement async controller or methods we need to derive controller from AsyncController rather than from normal plain Controller class. We need to create 2 action methods rather than one. First with suffix  ‘Async’ keyword & second with ‘Completed’ suffix.

In  ASP.NET MVC 4 you need not to declare 2 action method. One can serve the purpouse. MVC 4 using .Net Framework 4.5 support for asynchronous communication.

What are the main features of ASP.NET MVC 4 used by ASP.NET Web API?

  1. Routing changes: ASP.NET Web API uses same convention for config mapping that ASP.NET MVC provides.
  2. Model Binding & Validation: ASP.NET Web API uses same model binding functionality, but HTTP specific context related operations only.
  3. Filters: The ASP.NET Web API uses most of built-in filters from MVC.
  4. Unit Testing: Now Unit testing based on MVC, strongly unit testable.

What is the use of Display Modes in MVC?

View can be changed automatically based on browser (For mobile and desktop browser’s)

Display Modes is newly added feature in ASP.NET MVC 4. Views selected automatically by application depending on the browser.

Example: If a desktop browser requests login page of an application it will return Views\Account\Login.cshtml view & if a mobile browser requests home page it will return Views\Account\ view.

What is engine in ASP.NET MVC? What are different engines available

Engine is parser for your code. There are two type of engines avaible. You can choose any one.

  1. ASPX Engine
  2. Razor Engine

How to implement Windows authentication for MVC?

For Windows authentication you need to modify the web.config file and set the authentication mode to Windows.

<authentication mode="Windows"/>
<deny users="?"/>

Then in the controller or on the action, you can use the Authorize attribute which specifies which users have access to these controllers and actions. Below is the code snippet for that. Now only the users specified in the controller and action can access it.

[Authorize(Users= @"SystemName\Administrator")]
public class StartController : Controller
    [Authorize(Users = @"SystemName\Administrator")]
    public ActionResult Index()
        return View("MyView");

Hope this helps!!!

Similar Tags