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

81
Views
enlazar datos usando json mehod y js

Estoy tratando de recuperar datos en la lista desplegable, usando json, el programa funciona pero la lista desplegable muestra una lista blanca, al inspeccionar, los datos están allí pero no se muestran

Controlador:

 public IActionResult GetClient() { var clientList = (from client in _context.Clients select new SelectListItem() { Text = client.Nom, Value = client.Id.ToString(), }).ToList(); clientList.Insert(0, new SelectListItem() { Text = "----Select----", Value = string.Empty }); return Json(clientList); }

guion:

 <script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "GET", url: "/Clients/GetClient", success: function (data) { $.each(data, function () { $("#ClientId").append($("<option></option>").val(this['Value']).html(this['Text'])); }); } }); }); </script>

código HTML:

 </div> <div class="alert-danger" asp-validation-summary="ModelOnly"></div> <label asp-for="ClientId"></label> <select asp-for="ClientId" class="form-control" asp-items="@(new SelectList(Enumerable.Empty<SelectListItem>(),"Value", "Text"))"> </select> </div> <div>

Gracias por tu ayuda

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"The dropdownlist displays a white list, by inspecting, the data is there but it is not displayed"

El problema es muy obvio. Si inspeccionas el HTML , te verán. El value y text en Lowercase pero que ha utilizado en su código en Block/Capital uppercase que es val(this['Value']).html(this['Text'])) . Como sabrá, las claves de objeto Json están en Lowercase - small alphabet de forma predeterminada.

ingrese la descripción de la imagen aquí

Nota: simplemente reemplace el fragmento a continuación para que resuelva su problema por completo.

Solución:

 $("#ClientId").append($("<option></option>").val(this['value']).html(this['text']));

Producción:

ingrese la descripción de la imagen aquí

Espero que te ayude en consecuencia para señalar tu problema.

about 4 years ago · Juan Pablo Isaza 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!