MVC

What is MVC?

MVC is a framework methodology that divides an application’s implementation into three component roles: models, views, and controllers. “Models” in a MVC based application are the components of the application that are responsible for maintaining state. Often this state is persisted inside a database (for example: we might have a Product class that is used to represent order data from the Products table inside SQL). “Views” in a MVC based application are the components responsible for displaying the application’s user interface. Typically this UI is created off of the model data (for example: we might create an Product “Edit” view that surfaces textboxes, dropdowns and checkboxes based on the current state of a Product object). “Controllers” in a MVC based application are the components responsible for handling end user interaction, manipulating the model, and ultimately choosing a view to render to display UI. In a MVC application the view is only about displaying information – it is the controller that handles and responds to user input and interaction.

What are the 3 main components of an ASP.NET MVC application?

  • M - Model
  • V - View
  • C - Controller
  • Data Contracts

In which assembly is the MVC framework defined?

System.Web.Mvc

Is it possible to combine ASP.NET webforms and ASP.MVC and develop a single web application?

Yes, it is possible to combine ASP.NET webforms and ASP.MVC and develop a single web application.

What does Model, View and Controller represent in an MVC application?

Model: Model represents the application data domain. In short the applications business logic is contained with in the model.

What is the greatest advantage of using asp.net mvc over asp.net webforms?

It is difficult to unit test UI with webforms, whereas views in mvc can be very easily unit tested.

Which approach provides better support for test driven development - ASP.NET MVC or ASP.NET Webforms?

ASP.NET MVC

What is Razor View Engine?

Razor view engine is a new view engine created with ASP.Net MVC model using specially designed Razor parser to render the HTML out of dynamic server side code. It allows us to write Compact, Expressive, Clean and Fluid code with new syntaxes to include server side code in to HTML.

What are the advantages of ASP.NET MVC?

  • 1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.
  • 2. Complex applications can be easily managed
  • 3. Seperation of concerns. Different aspects of the application can be divided into Model, View and Controller.
  • 4. ASP.NET MVC views are light weight, as they donot use viewstate.

Is it possible to unit test an MVC application without running the controllers in an ASP.NET process?

Yes, all the features in an asp.net MVC application are interface based and hence mocking is much easier. So, we don't have to run the controllers in an ASP.NET process for unit testing.

Name a few different return types of a controller action method?

The following are just a few return types of a controller action method. In general an action method can return an instance of a any class that derives from ActionResult class.

  1.  ViewResult
  2.  JavaScriptResult
  3.  RedirectResult
  4.  ContentResult
  5.  JsonResult