1
As I do to validate in the Exit of an Input, I already have the function that returns bool, if it returns false, I can’t let go of the seller.snome field and present an alert message.
<div class="row">
<div class="col-md-4">
<form asp-action="Editar">
<input type="hidden" asp-for="vendedor.idvendedor" />
<div class="form-group">
<label for="nome">Nome:</label>
<input asp-for="vendedor.snome" class="form-control" />
</div>
<div class="form-group">
<label for="email">E-Mail:</label>
<input asp-for="vendedor.semail" class="form-control" />
</div>
<div class="form-group">
<label for="datanascimento">Data de Nascimento:</label>
<input asp-for="vendedor.ddatanascimento" class="form-control" />
</div>
<div class="form-group">
<label for="salariobase">Salário Base:</label>
<input asp-for="vendedor.nsalariobase" class="form-control" />
</div>
<div class="form-group">
<label for="iddepartamento">Departamento:</label>
<select asp-for="vendedor.iddepartamento" asp-items="@(new SelectList(Model.departamentos, "iddepartamento", "snome"));" class="form-control"> </select>
</div>
<div class="form-group">
<input type="submit" value="Salvar" class="btn btn-default" />
<a asp-action="Index">Voltar</a>
</div>
</form>
</div>
uses the event onblur
– Ricardo Pontual
Would the function you have be in javascript anyway? To validate when leaving a field only with JS. Put the function you commented on the question.
– George Wurthmann
@Georgewurthmann, actually the function I have is in my services, with the validations and ifs, my question is, if this Function that is out of view, there in my Model return false, I display the warning message. However, I have no idea how to call this Function in the view.. I imagine I should call with JS, however, I do not know how to do this.
– Jd3 Tecnologia
@Ricardopunctual I came to see about the event, my problem, is not knowing how to make this call, looking at a Function out of view, there my model, where have my business rules.
– Jd3 Tecnologia
Services would be a layer of your project? You seem to be mixing things up. If so, this validation is from the backend and you should do it too, but it will be called in your controller at some point. The validation you are asking in the question is frontend and you should do by javascript.
– George Wurthmann
@Georgewurthmann managed to find documentation exactly for what I need, it’s called Remotevalidation in Asp.Net, I create Function in my backend layer, and in my attribute class I call parameter [Remote(action: "My Deep",controller: "Meucontroller")]
– Jd3 Tecnologia
@Jd3technology So it would be cool for you to write an answer so that your question and solution can help other people in the future.
– Leandro Angelo
@Leandroangelo I’m new in the community, thanks for the tip, I’ll reply to close! Thanks!
– Jd3 Tecnologia