Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Mostrar correctamente los datos de AJAX (ASP.NET MVC)

Tengo este código en el controlador de back-end

 [HttpGet] public ActionResult EmailsList() { var itemsEmail = db.InvitationMails .Select(x=> new { Email = x.To.ToString(), Name = x.Name.ToString(), }) .ToList(); return Json(itemsEmail, JsonRequestBehavior.AllowGet); }

Esto en el código de llamada AJAX

 <script> $('#save_quest').click(function () { email_update(); }); function email_update() { $.ajax({ url: '@Url.Action("EmailsList", "Questions")', contentType: 'application/json; charset=utf-8', type: 'GET', dataType: 'json', processData: false, success: function (result) { var email = result; // console.log(result[0].Name); for (var i = 0; i <= email.length - 1; i++){ var emailHTML = '<div style="margin-left: 25px; margin-top: 10px;>' + '<b style="margin-left: 10px;">' + result.Email + '<b>' + '<b style="margin-left: 20px;">' + result.Name + '</b>' + '</div>' $(".email_list").append(emailHTML); } } }); }

El código funciona bien, pero tengo undefined en Ver.

ingrese la descripción de la imagen aquí

¿Cómo necesito editar mi código para mostrarlo correctamente?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Estoy escribiendo esto para ayudar a alguien si tiene el mismo problema,

Debido a que es una matriz de objetos, debe agregar [i] con su resultado dentro de su ciclo for.

 for (var i = 0; i <= email.length - 1; i++) { var emailHTML = '<div style="margin-left: 25px; margin-top: 10px;>' + '<b style="margin-left: 10px;">' + result[i].Email + '<b>' + '<b style="margin-left: 20px;">' + result[i].Name + '</b>' + '</div>' $(".email_list").append(emailHTML); }

Salud :)

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!