Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda