Good People I try to access the data of this html table in an ASP.NET view I can only access the data of one line but I cannot access the data of the other rows of the tbody, I have tried with several methods but I can not access data
I am using this Script to iterate the elements inside the table but it drops when I try to do the second iteration
<script>
$("#btnDatos").click(function () {
'use strict'
const tBody = document.getElementById('tableResultContent').children;
for (let j = 0; j < tBody.length; j++) {
const tablerow = tBody[j];
console.log("Table Row = ", tablerow);
for (let i = 0; i < tablerow.length; i++) {
var td = document.getElementsByTagName("td")[i].innerHTML;
console.log(td);
$.ajax({
type: "GET",
url: 'ListarPedido',
data: { listaPedido: td },
success: function (data) {
console.log(data);
$("#txtListado").val(data.listadoFinal);
}
});
}
}
})
Controller code that receives the script request
[HttpPost]
public JsonResult ListarPedido(string listaPedido)
{
var listado = listaPedido.ToString();
var listaPedidoViewModel = new PedidoViewModel()
{
NombrePedProducto = "Nombre",
UnidadMedida = "Unidad",
Precio = 10,//decimal
Stock = 10,//decimal
Cantidad = 10,//decimal
Descuento = 10,//decimal
Observacion = "Obs",
Total = 10,//decimal
};
return Json(new { listaPedidoViewModel }, JsonRequestBehavior.AllowGet);
}
From this:
you go to this
You have an Ajax call on each iteration. I did not understand the reason
To fetch and loop through the rows you do something like this:
Your controller should be something like this