C# and Http nowadays are becoming very connected. In ASP.NET C# is the major backend server-side programming language.
While front-end frameworks are popping up more and more often, server-side programming languages are more or less always the same.
In this article, I am going to explain the MVC approach used in ASP.NET web applications. I will provide you with a general overview without going too deep into the technical side and I will clarify the relationship between C# and HTTP.
MVC stands for “Model, View, Controller”. These represent the 3 pillars of the MVC approach.
The view is the UI that will be shown to the user. This UI is basically the HTML markup. The role of the view is “how” to show.
The controller is a C# class. It tells the view “what” to show. This happens through an Http web request. The controller will fill the data in the view using the model.
The model is also a C# class. It tells the controller and the view “which shape” the data should have.
A practical example
Let’ s do an example to explain all the above concepts. Our HTML page is showing a list of animals. For each of them is giving the name and the race.
Talking in MVC words this means:
- View: iterate through the array of animals and display it in a list
- Controller: retrieve data and shape them in an array of animal
- Model: the animal. It has 2 properties: name and race
The advantges of MVC approach
Separating the UI layer from the business logic brings an enormous advantage. One is the separation of duties between different developers. I worked often in MVC environments. When you have to collaborate with other people, the MVC is the best solution.
You can really tackle the business logic without having concerns on the UI, that can be then tackled apart by the other person at the same time. This improves the speed of the development and, according to me, is less error-prone.