What is MVC? Why use MVC?

dotnettrick

Dotnettricks

Posted on October 6, 2020

What is MVC? Why use MVC?

It's a vast topic to cover. Explain what MVC is. It's just a three-tier architecture, where M stands for model, and V stands for view, and the most essential part of this architecture, like any other movie hero, is the controller. Therefore, each layer of MVC has its own responsibility. Therefore, views are intended for both appearance and placement of what the end-user sees.

The model provides the data and business logic. Thus, the model is just a class like employees, students, and so on. The model can interact with the data access layer, which is a service, such as a WCF service or web service that provides data. The controller is the heart of the MVC course, and as mentioned earlier, as a movie hero, it handles both layers. Therefore, the controller is also called the coordinator between the model and the view.

In MVC, when a user submits a request from a web browser, the controller is reached first. The controller sends it to the corresponding view. As mentioned earlier, the model always carries data, so the data request is sent by the user, and the controller is sent to the model class. If you change one layer, all the other layers remain the same. This is the main advantage of perfecting MVC. Here, the second figure illustrates a controller folder with a controller file extension. This folder also contains a model folder with the client-vendor class.

Here, it is the controller's responsibility to send the information from the model sent to the view. Now let's talk about the reasons why to use MVC. Why is MVC as reliable as a web form? Let's explain why MVC alone doesn't have web forms. Let's take a look at some background approaches to ASP.NET. This image illustrates more scenarios of the
differences between MVC forms and web forms.

Let's start with Microsoft in the background of Windows. These languages ​​have no visual effect, so if you want to modify a button in C ++, you need to actually write the code. So Microsoft challenged what was called visual programming or RAD programming and set it up instead of the programmer code. To create the window, Microsoft introduced the following box: tool. They released Visual Studio and again in the programming language, and Microsoft was successful.
MVC training has the best scope shortly.
RAD programming is excellent, but it does cause some problems. The problem is in the backend of the code. That is, when the programmer drags and drops, the code is generated in subclasses. Let's analyze some of the shortcomings of this RAD programming.

Issue # 1: View-based architecture for action-based requirements.

When a user submits an action, what happens in the page lifecycle is that the lifecycle simply calls a complex structure, and you can see that the page is loading and other types of life cycles are in progress. It's a complicated method now. This is a mandatory event, not an event that runs any other occasion. Therefore, when an end-user submits a request as an action in this scenario, they first go to the view and then go through the complex life cycle again. In other words, you experience a complex life cycle, but the logical approach is to go to the stock directory. When a user submits an action request, it is mapped to a method in the program, the process is called, all the logic needed for the action is executed, then the required view is called, which is what happens in MVC.

Problem 2: Behind code cannot be reused.

So the related problem in choosing a lousy architecture was that the RAD architecture couldn't be used because the underlying code couldn't be reused. Still, MVC allows you to code reusable code over and over again.

Problem 3: Flexible combination of views and data

In short, web forms are a view-based architecture. The view is always determined, but in MVC, it ​​hits the controller first, so it's more likely to join in MVC, but not in web forms. This is because the view is always fixed.

Problem 4: Behind the code

There is an easy way to unit test in MVC, an option for unit testing after creating a new project, but it's very difficult to handle on the web.

💖 💪 🙅 🚩
dotnettrick
Dotnettricks

Posted on October 6, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related