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.
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:
4. Explain “page lifecycle” of an ASP.NET MVC?
Following process are performed by ASP.Net MVC page:
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:
6. What are the new features of MVC4?
Following are the top features of MVC4:
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?
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]