Iteanz Interview Questions | Latest Technologies Interview Questions

MVC Interview Questions and Answers For 2 Years Experience

Written by Bharathkumar | Sep 10, 2022 4:45:06 PM

 

 

1. What do you meant MVC?
MVC is a framework pattern that splits an application’s implementation logic into
three component roles: models, views, and controllers.

  • Model: The business entity on which the overall application operates. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be encapsulated by the Model.
  • View: The user interface that renders the Model into a form of interaction.
  • Controller: Handles a request from a View and updates the Model that results in a change of the Model’s state.

To implement MVC in .NET we need mainly three classes (View, Controller and the Model).

2. What is meant by ASP.Net MVC
The ASP.Net MVC is the framework provided by Microsoft to achieve     separation of concerns that leads to easy maintainability of the     application.
Model is supposed to handle data related activity
View deals with user interface related work
Controller is meant for managing the application flow by communicating between Model and View.

3. What are the new features of MVC2?
ASP.NET MVC 2 was released in March 2010. Its main features are:

  1.     Introduction of UI helpers with automatic scaffolding with customizable templates.
  2.     Attribute-based model validation on both client and server.
  3.      Strongly typed HTML helpers.
  4.      Improved Visual Studio tooling
  5.     There were also lots of API enhancements and “pro” features, based on feedback from developers building a variety of applications on ASP.NET MVC 1, such as:
  •  Support for partitioning large applications into
  •  Asynchronous controllers support.
  •  Support for rendering subsections of a page/site using Html.RenderAction.
  •  Lots of new helper functions, utilities, and API enhancements

4. Explain “page lifecycle” of an ASP.NET MVC?
Following process are performed by ASP.Net MVC page:

  1. App initialization
  2. Routing
  3. Instantiate and execute controller
  4. Locate and invoke controller action
  5. Instantiate and render view

5. What are the new features of MVC3?
ASP.NET MVC 3 shipped just 10 months after MVC 2 in Jan 2011.Some of the top features in MVC 3 included:

  •      The Razor view engine.
  •      Support for .NET 4 Data Annotations.
  •      Improved model validation
  •      Greater control and flexibility with support for dependency resolution and global action filters.
  •      Better JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding.
  •      Use of NuGet to deliver software and manage dependencies throughout the platform.

6. What are the new features of MVC4?
Following are the top features of MVC4:

  •     NET Web API.
  •     Enhancements to default project templates.
  •     Mobile project template using jQuery Mobile.
  •     Display Modes.
  •     Task support for Asynchronous Controllers.
  •     Bundling and minification.

7. Why to use ASP.Net MVC
The strength of MVC (i.e. ASP.Net MVC) is listed below, that will answer this question
MVC reduces the dependency between the components; this makes your code more testable.
MVC does not recommend use of server controls, hence the processing time required to generate HTML response is drastically reduced.
The integration of java script libraries like jQuery, Microsoft MVC becomes easy as compared to Webforms approach.

8. Advantages of MVC Framework?

  1. Provides a clean separation of concerns between UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
  2. Easy to UNIT Test.
  3. Improved reusability of views/model. One can have multiple views which can point tosame model and vice versa.
  4. Improved structuring of the code.

9. What do you mean by Razor
The Razor is the new View engine introduced in MVC 3.0.
The View engine is responsible for processing the view files [e.g. .aspx, .cshtml] in order to generate HTML response.
The previous versions of MVC were dependent on ASPX view engine.

10. What do you mean by Separation of Concerns?
As per Wikipedia ‘the process of breaking a computer program into distinct features that overlap in functionality as little as possible’. MVC design pattern aims to separate content from presentation and data-processing from content.

11. Can we use ASPX view engine in latest versions of MVC
Yes. The Recommended way is to prefer Razor View

12. Where do we see Separation of Concerns in MVC?
Between the data-processing (Model) and the rest of the application.
When we talk about Views and Controllers, their ownership itself explains separation. The views are just the presentation form of an application, it does not have to know specifically about the requests coming from controller. The Model is independent of View and Controllers, it only holds business entities that can be passed to any View by the controller as required for exposing them to the end user. The controller is independent of Views and Models, its sole purpose is to handle requests and pass it on as per the routes defined and as per the need of rendering views. Thus our business entities (model), business logic (controllers) and presentation logic (views) lie in logical/physical layers independent of each other.

13. What are the benefits of Razor View?
The syntax for server side code is simplified
The length of code is drastically reduced
Razor syntax is easy to learn and reduces the complexity

14. What is the extension of Razor View file?
.cshtml (for c#) and .vbhtml (for vb)

15. What are Display Modes in MVC4?
Display modes use a convention-based approach to allow selecting different views based on the browser making the request. The default view engine fi rst looks for views with names ending with .Mobile.cshtml when the browser’s user agent indicates a known mobile device. For example, if we have a generic view titled Index.cshtml and a mobile view titled Index.Mobile.cshtml, MVC 4 will automatically use the mobile view when viewed in a mobile browser.

Additionally, we can register your own custom device modes that will be based on your own custom criteria — all in just one code statement. For example, to register a WinPhone device mode that would serve views ending with .WinPhone.cshtml to Windows Phone devices, you’d use the following code in the Application_Start method of your Global.asax:

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode(“WinPhone”)

{

ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf

(“Windows Phone OS”, StringComparison.OrdinalIgnoreCase) >= 0)

});

16. How to create a Controller in MVC
Create a simple class and extend it from Controller class. The bare minimum requirement for a class to become a controller is to inherit it from ControllerBase is the class that is required to inherit to create the controller but Controller class inherits from ControllerBase.

17. What is AuthConfig.cs in MVC4?
AuthConfig.cs  is used to configure security settings, including sites for OAuth login.

18. How to create an Action method in MVC
Add a simple method inside a controller class with ActionResult return type.

19. How to access a view on the server 
The browser generates the request in which the information like Controller name, Action Name and Parameters are provided, when server receives this URL it resolves the Name of Controller and Action, after that it calls the specified action with provided parameters. Action normally does some processing and returns the ViewResult by specifying the view name (blank name searches according to naming conventions).

20. What is the default Form method (i.e. GET, POST) for an action method
GET. To change this you can add an action level attribute e.g [HttpPost]