Learn ASP.NET MVC & Entity Framework

Step-by-Step tutorials on ASP.NET MVC and Entity Framework for Beginners


| Comments

In this post, we will introduce you to ASP.NET MVC.

ASP.NET MVC is an amazing web development framework from Microsoft, which is built on top of the MVC (Model-View-Controller) architectural pattern.

It is built on the top of the same ASP.NET core libraries used by traditional ASP.NET Webforms. It is not a replacement for ASP.NET WebForms.

ASP.NET MVC was created by Scott Guthrie in the year 2007. Just like WebForms, MVC leverages the benefits of the ASP.NET core features like caching, modules, handlers, session state, query strings and etc.

The MVC architectural pattern can be dated back to 1979 when it was used with the Smalltalk programming language. As ASP.NET MVC follows the MVC architectural design pattern the application is separated into 3 main components i.e. Models, Views, and Controllers.

Model: Models are classes that model the data of the application. In simple words, it describes the data you are working with as well as the business logic.

View: View defines how the application’s user interface looks like. Views are the presentation layer that displays the data returned by the Model classes using any data access framework like Entity Framework or ADO.NET library.

Controller: Controllers are classes that process incoming requests, obtain data from model classes using Entity framework and then return data to a view to render data using the razor view engine and razor syntax. The controller processes the requests with the help of views and models.

In simple words, a controller’s job is to handle communication from the user (via a View) into the Model object and as the Model classes are used by Entity Framework the data can be saved or persisted in the database with ease. When rendering the data in the view, the model object data will be passed to the view by the controller.

Benefits of ASP.NET MVC

  • All the layers are loosely coupled. As in MVC, the whole application is separated into Models, Views, and Controllers. All the individual components are isolated from each other. This separation of layers is known as Separation of concern (SOC).
  • With SOC everything can be easily tested. Using TDD(Test driven development) controllers, models and view can be individually tested. This kind of testing is not possible in WebForms as it doesn’t support the principle of SOC.
  • As every component is isolated from each other MVC forces developers to do concurrent development i.e. one developer can work on views, another can work on models, controllers and entity framework related code.
  • Extensibility: Individual components of the MVC framework is built using an interface or an abstract base class so that developers can easily replace components with a different one of their own implementations.
  • MVC framework also provides tight control over the HTML with the help of HTML Helper methods which generate standard-complaint HTML markup.