MVC Interview Questions


Q#1. What is MVC (Model view controller)?

Ans. Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representation of information from the way that information is presented to or accepted from the user.


Q#2. Explain in which assembly is the MVC framework is defined?

Ans. The MVC framework is defined in System.Web.Mvc.


Q#3. What Is The Use Of View Model In Asp.net Mvc?

Ans. View Model is a plain class with properties, which is used to bind it to strongly typed view. View Model can have the validation rules defined for its properties using data annotations.


Q#4. Mention what is the difference between adding routes, to a webform application and an MVC application?

Ans. To add routes to a webform application, we can use MapPageRoute() method of the RouteCollection class, where adding routes to an MVC application, you can use MapRoute() method.


Q#5. What Are Actions In Asp.net Mvc?

Ans. Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type : "ActionResult" and it will be invoked from method : "InvokeAction()" called by controller.


Q#6. Mention what is the advantages of MVC?

Ans. MVC segregates your project into a different segment, and it becomes easy for developers to work on It is easy to edit or change some part of your project that makes project less development and maintenance cost MVC makes your project more systematic


Q#7. Explain what is the difference between View and Partial View?

Ans. View It contains the layout page. Before any view is rendered, viewstart page is rendered. View might have markup tags like body, html, head, title, meta etc. View is not lightweight as compare to Partial View. Partial View It does not contain the layout page. Partial view does not verify for a viewstart.cshtml.We cannot put common code for a partial view within the viewStart.cshtml.page. Partial view is designed specially to render within the view and just because of that it does not consist any mark up. We can pass a regular view to the RenderPartial method.


Q#8. Explain Dependency Resolution?

Ans. Dependency Resolver again has been introduced in ASP.Net MVC3 and it is greatly simplified the use of dependency injection in your applications. This turn to be easier and useful for decoupling the application components and making them easier to test and more configurable.


Q#9. Explain Filters? Which one executes in the last?

Ans. Filters are used to define logic that should be performed either after or before action method execution. Some MVC filters are: ? Exception filter ? Action filter ? Authorisation filter ? Result filter


Q#10. What Is Viewdata?

Ans. Viewdata contains the key, value pairs as dictionary and this is derived from class : "ViewDataDictionary". In action method we are setting the value for viewdata and in view the value will be fetched by typecasting.