I have a better introduction for you.
I’d like to understand where the whole code between the Controller and the Model until the seat is inserted.
Well, you have just answered a part of your own question. I will now go into more technical detail.
Your form has a action, which is the same name as the method in Controller (which, incidentally, we also call Action). For example:
[HttpPost]
public ActionResult MinhaAcao(MeuViewModel viewModel)
{
...
}
Your form, in case, would need to be like this:
<form id="form1" action="/MeuController/MinhaAcao">
The field names reflect what the Model or Viewmodel receives. For example, your field:
<input type="text" class="form-control" id="inputNome" name="name" placeholder="Título">
The name
his is "name"
, then the Viewmodel need to have:
public class MeuViewModel
{
public String name { get; set; } // O campo precisa ter exatamente o mesmo valor do atributo "name" do formulário
...
}
The assignment of the sent values is done automatically through a functionality of ASP.NET MVC called Model Binding.
In case, your form is wrong because it has two <input>
s with the same "name"
(with, in fact, the value "name").
Supposing now that you have corrected your form and made a test to send data to the Controller. If you filled one out Viewmodel and is using Entity Framework, you will have to fill a Model also to enter or update the information in the database, or you may receive a Model filled out the form directly. Some disagree that this is safe, so some currents discourage the use of Models directly into forms. Opinionated speaking, I find it safe because there are ways to check the Model before inserting, using, for example, [Bind]
.
If you are not using Entity Framework, just read the values of the Model or Viewmodel and put it in the bank any way you want.
I won’t lengthen the answer about the Entity Framework because you don’t need to. If you want to know more, ask another question or express yourself by comments.
Just complementing @Gypsy’s response, maybe this tutorial can help you understand how to do this. If you have any questions, let me know if I can come up with a response.
– Randrade
As soon as possible I will be reading about @Randrade. Vlw too much. More if you want to risk an answer send see.
– Marconi
Hello, for you who are starting I suggest you watch the video lessons of Cleyton Ferrari > https://www.youtube.com/user/cleytonferrari/
– Oziel Guimarães