I have two tables in a view, one of them is hidden and appears when I click on a row in the first table
Hidden table:
@model Tuple<IEnumerable<web.Areas.Periodo.Models.PeriodoViewModel>,
IEnumerable<web.Areas.Periodo.Models.PeriodoPagoViewModel>>
<div id="SegundaTabla" style="display:none">
<div class="row">
<div class="col-md-12">
<div class="portlet box">
<div class="portlet-title">
<div class="caption">
<div class="tools">
<a href="javascript:;" class="collapse" data-original-title="" title=""> </a>
</div>
</div>
<table class="table table-striped table-hover table-bordered dt-responsive" width="100%" id="tbl-listado">
<thead>
<tr>
<th data-priority="1"> Periodo Pago </th>
<th data-priority="2"> Estatus </th>
</tr>
</thead>
<tbody>
<tr>
<tbody>
<tr>
@if (Model.Item2 != null) { foreach (var item in Model.Item2) {
<tr class="select" id="@item.IdPeriodoPago">
<td>@item.sTipoPeriodo</td>
<td>@item.Estatus</td>
</tr>
} }
</tbody>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
To make the table appear, I do it by changing the class with a simple jQuery (changing the property display
of css):
$('.select').each(function (index) {
$(this).click(function () {
var row = $(this);
var id = row.attr('id').split('-')[1];
row.css({ 'background-color': 'aqua' });
$('#SegundaTabla').css({ 'display': 'block' });
$.ajax({
url: '/Periodo/Periodo/IndexSelect',
type: 'POST',
data: { id: id }
});
});
});
Controlador:
[HttpPost]
public ActionResult IndexSelect(int? id)
{
List<PeriodoPagoViewModel> LPGVM = new List<PeriodoPagoViewModel>();
var lista2 = PPS.Listar(x=>x.IdPeriodoMensual == id && x.EstatusRegistro, includeProperties: "TipoPeriodo");
foreach (var l in lista2)
{
PeriodoPagoViewModel PVM = new PeriodoPagoViewModel();
PVM.sTipoPeriodo = l.TipoPeriodo.Nombre;
if (l.Estatus == "A")
PVM.Estatus = "Abierto";
else if (l.Estatus == "X")
PVM.Estatus = "Calculado";
else if (l.Estatus == "C")
PVM.Estatus = "Cerrado";
else if (l.Estatus == "P")
PVM.Estatus = "Pendiente";
else
PVM.Estatus = "";
LPGVM.Add(PVM);
}
return View("Index", LPGVM);
}
The controller returns the LPGVM
object with a list of objects. Therefore, the flow is as follows:
Click on the first table, this table sends the id to the controller and the controller returns the list of objects. My question is: What do I have to do to make my table fill up once I click on the first table and the controller returns the list of objects?
How do I get the objects in the view and then show them in the body of my table? Thanks!
I tried adding the success property in my ajax call:
$.ajax({
url: '/Periodo/Periodo/IndexSelect',
type: 'POST',
data: { id: id },
success: function (response)
{ alert(response.status); }
but it returns to me:
success is not defined
then I tried the following:
$.ajax({
url: '/Periodo/Periodo/IndexSelect',
type: 'POST',
data: { id: id },
success: handleResponse
function handleResponse(data) { alert(data); }
But it does not work either. Can anybody help me? Greetings