MVC: Model, View, Controller.
Model: Application logic layer is where you put your application’s business rule (using C# or Vb.net for example) is where you manage data, logic and application rules.
View: Responsible for displaying your page, it needs to be compiled in real time, after which it generates an HTML. The coding gives through the programming language you will be able to popular the HTML with the data brought from the Controller.
Controller: This is where the requests are processed, captures the received data in order to pass it to the Model that will respond with data (if necessary), once received the data, the Controller must respond is by returning raw data through JSON
for example or by returning a View with data.
How does the cycle work in practice? (Example in ASP.NET MVC C#)
- The user accesses the page www.google.com and type Stackoverflow;
1° Controller will receive a Model with the data entered in the form of the Google page.
public ActionResult Index(SearchModel search) //Passo 1 - A pesquisa se encontra dentro do Model enviado para o Controller
{
search.SearchResponse = search.Search(); //Passo 2 - Método Search() retorna o objeto SearchResponse para dentro da própria classe SearchModel
return View(search); //Passo 3 - O model é retornado para a camada de visualização (View)
}
2° Model when called through the Controller processes logic and responds with what was requested.
public class SearchModel
{
public String SearchInput {get;set;}
public SearchResponse SearchResponse {get;set;}
public SearchResponse Search()
{
//Lógica do método Search
}
}
3°A View processes the data brought from Controller which were processed in Model.
<body>
@foreach(SearchResult result in Model.SearchResponse.SearchResult)
{
<p>@result.Description</p>
}
</body>
4° User browser receives the following:
<body>
<p>Stack Overflow é um website de capital fechado, o site principal da Rede Stack Exchange. Foi criado em 2008 por Jeff Atwood e Joel Spolsky como uma ...</p>
<p>Over the weekend, there was an attack on Stack Overflow. We have confirmed that some level of production access was gained on May...</p>
</body>
These are just practical examples of answers, the HTML is returned in a complete way (with <html>
,<head>
and everything else that was set in its Layout)
On this page from Microsoft also gives to have a basic notion of how things work.
Pedro C., I suggest you study some pages in the web of computers. Examples: ASP . NET 4.5 Web Forms - Creating the Project - I (Beginning of the Course) ASP . NET Core - Creating an ASP . NET Core MVC application with VS 2017 ASP . NET Core 2.0 - Basic Mini-course ASP NET Course with MVC - Aula 01 - ASP.NET C# and MVC
– FabioIn