Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Jquery - MVC - Functionname is not defined at HTMLButtonElement.onclick

I searched this error and tried other people`s solution but it does not fixed.I changed jquery versions , write code from beginning vs vs but still same.

 [HttpPost]
    public JsonResult GetID(int ID)
    {
        List<User> users = db.users.ToList();
        User user = users.FirstOrDefault(x => x.Id == ID);
        return Json(user, JsonRequestBehavior.AllowGet);
    }



 <button onclick="dataget()" id="personID" style="margin-left: 28%;"> <span class="fa fa-arrow-left text-dark" style="font-size:30px" aria-hidden="true"></span></button>


<script type="text/javascript">

    var dataget = function () {
        var ID = 1;
        $.ajax({
            url: '/Finder/GetID/' + ID,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                $("#Name").html(data.Name);
                $("#Surname").html(data.Surname);
            }

        });
</script>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use this as your button;

 <button id="personID" style="margin-left: 28%;"> ... </button>

You should place your script inside a razor section, it will be inserted into the script section in your layout.

 @section script { <script type="text/javascript"> // execute this function upon page ready $(document).ready(function(){ // bind the event to your button $("#personID").click(function(e){ e.preventDefault(); //Fetch form data var sendData = { ID:1 }; $.ajax({ url: '@Url.Action("Find","GetID")', type: 'POST', data: sendData, dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (data) { $("#Name").html(data.Name); $("#Surname").html(data.Surname); } }); }); }); </script> }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda