Already we have worked with the presentation of the data, and now is the moment to validate that the data that enter are correct, for afterwards store it (this will be in the next session).
To validate the data will have to press the button store and ¿to where carries us the surroundings?. Pues To any place because we have to create a new method that gestione the information entered. This method has to call equal that the one of presentation but with a series of difference.
We Will have to happen like parameter the model with which have worked in the edition, in our case catalogador
It has to include, with a definition, that the data receive by POST. This achieves putting [HttpPost] before the statement of the method
Therefore the result would be the following
Control in an exception all the logic of storage. First we validate, in correct case will store the data and in contrary case showed again the sight.
If we tested it will see that it works and that redirects us to the method Index, that if we have defined properly (including the sight) will see that it carries us there, because the model has been validated.
The question that do us now is, ¿what validates?. We have not defined any rule that have to fulfil our model.
Rules of validation
To assign rules, have to acudir again to the model and begin to add definitions. Stop can add them have to include the spaces of names
So that we can use the attributes of validation.
We go to put a very basic, that was compulsory the field CSS [Required].
Also in occasions does not like us that it appear as it labels the name of the field of the model, if no that we want an own description in the case of Css want to that it was Leaf of styles [DisplayName].
If we generated the solution and edited, will see that already remains reflected the new description
Besides if we do not put any value in the field Leaf of style and pressed the button Update, will observe that it appears us a message of error.