Validation Input Aspnetmvc

Asked

Viewed 41 times

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>

  • 1

    uses the event onblur

  • 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.

  • @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.

  • @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.

  • 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.

  • 1

    @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")]

  • @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.

  • @Leandroangelo I’m new in the community, thanks for the tip, I’ll reply to close! Thanks!

Show 3 more comments

1 answer

0


Validation, called Remotevalidation in Asp.Net, creates Function in the service layer (Backend, and in the attribute class call parameter -[Remote(action: "MinhaFuncao",controller: "MeuController")]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.