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

93
Views
Quiero mostrar el valor uno por uno en el bucle foreah según la imagen de demostración

ingrese la descripción de la imagen aquí

En un modelo con 180 registros, quiero mostrar uno a la vez. cuando hago clic en el siguiente botón, se muestra el siguiente registro con una página actualizada.

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

0

Puede intentar usar TempData y vista parcial, aquí hay una demostración:

Modelo:

 public class LoopModel{ public List<string> l { get; set; } public int count { get; set; } }

Acción:

 [HttpGet] public IActionResult TestLoop() { LoopModel loopModel = new LoopModel { l = new List<string> { "s1", "s2", "s3", "s4", "s5" }, count = 0 }; TempData["model"] =JsonConvert.SerializeObject(loopModel); return View(); } [HttpPost] public IActionResult TestLoop(int count) { var s = TempData.Peek("model").ToString(); LoopModel loopModel = JsonConvert.DeserializeObject<LoopModel>(TempData.Peek("model").ToString()); if(count<loopModel.l.Count()) loopModel.count = count; return PartialView("Partial1",loopModel); }

TestLoop.cshtml:

 @using Newtonsoft.Json; <div id="myDiv"> @await Html.PartialAsync("Partial1", JsonConvert.DeserializeObject<LoopModel>(TempData.Peek("model").ToString())) </div> <button onclick="AddContent()">next</button> @section Scripts { <script> var count = 0; function AddContent() { count++; $.ajax({ type: "POST", url: '?count=' + count, success: function (result) { $("#myDiv").html(result); } }); } </script> }

Parcial1:

 @model LoopModel @for (var i = 0; i <= Model.count; i++) { <div class="container">@Model.l[i]</div> }

resultado: ingrese la descripción de la imagen aquí

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!