How to save dynamic checkbox and textbox with a single button in MVC .Net

0

For each row of the records of my sql table in the view I add two checkboxes and a textbox to later save what has been selected and entered in the textbox, as I can know the checkboxes that were selected, the textbox text since data_id belongs the data.

my eyesight

<div class="jumbotron">
    <table class="table responsive shopex-table table-hover no-margin">
        <thead>
            <tr>
                <th>Id Pago</th>
                <th>Id Cliente</th>
                <th>Nombre cliente</th>
                <th>Monto</th>
                <th>Monto en Dólares</th>
                <th>% comisión cliente</th>
                <th>% comisión a pagar</th>
                <th>Autorización</th>
                <th>Rechazo</th>
                <th>Comentario Rechazo</th>
                <th>Fecha</th>

            </tr>
        </thead>
        <tbody>

            @foreach (var item in Model)
            {
                double montoDolares = Convert.ToDouble(item.Pagos.Monto) * 13.25;
                decimal comisionPagar = Convert.ToInt32(item.Cliente.Comision) * item.Pagos.Monto;

                <tr>
                    <td class="vcenter">
                        @item.Pagos.IdPago
                    </td>
                    <td class="vcenter">
                        @item.Pagos.IdCliente
                    </td>
                    <td class="vcenter">
                        @item.Cliente.Nombre
                    </td>
                    <td class="vcenter">
                        @item.Pagos.Monto
                    </td>
                    <td class="vcenter">
                        @montoDolares
                    </td>
                    <td class="vcenter">
                        @item.Cliente.Comision
                    </td>
                    <td class="vcenter">
                        @comisionPagar
                    </td>
                    <td style="text-align:center">              
                        @Html.CheckBox("Autoriza", false, htmlAttributes: new { @class = "chkAutoriza" })
                    </td>
                    <td style="text-align:center">            
                        @Html.CheckBox("Rechaza", false, htmlAttributes: new { @class = "chkRechaza"})
                    </td>
                    <td class="vcenter">
                        @Html.TextBox("StudentName", null, new { @class = "form-control"})
                    </td>
                    <td class="vcenter">
                        @item.Pagos.Fecha.ToString("dd/MM/yyyy")
                    </td>

                    <td class="vcenter text-right"></td>
                </tr>
            }
        </tbody>
    </table>

    <button class="btn btn-success">Autorizar</button>

</div>
    
asked by Ivxn 21.07.2018 в 05:49
source

1 answer

0

        $('#btnGuardar').click(function () {
            $(this).parent().find('.idPago').each(function () {

                var valorCheck = $(this).parent().parent().parent().parent().parent().parent().parent().parent().find('#chkAutoriza' + idPago.trim()).is(':checked');
                var valorComentario = $(this).parent().parent().parent().parent().parent().parent().parent().parent().find('#txtComentario' + idPago.trim()).val();
                var valorFecha = $(this).parents("tr").find("td")[10].innerHTML;
});
});
<div class="jumbotron" style="font-size:small">
    <table class="table responsive shopex-table table-hover no-margin">
        <thead>
            <tr>
                <th>Id Pago</th>
                <th style="display:none">Id Cliente</th>
                <th>Nombre cliente</th>
                <th>Monto</th>
                <th>Monto en Dólares</th>
                <th>% comisión cliente</th>
                <th>% comisión a pagar</th>
                <th>Autorización</th>
                <th>Rechazo</th>
                <th>Comentario Rechazo</th>
                <th>Fecha</th>

            </tr>
        </thead>
        <tbody>

            @foreach (var item in noAutorizados)
            {
                double montoDolares = Convert.ToDouble(item.Pagos.Monto) * 13.25;
                decimal comisionPagar = Convert.ToInt32(item.Cliente.Comision) * item.Pagos.Monto;

                <tr>
                    <td class="idPago">
                        @item.Pagos.IdPago
                    </td>
                    <td class="vcenter" style="display:none">
                        @item.Pagos.IdCliente
                    </td>
                    <td class="vcenter">
                        @item.Cliente.Nombre
                    </td>
                    <td class="vcenter">
                        @string.Format("{0:n}", item.Pagos.Monto)
                    </td>
                    <td class="vcenter">
                        @string.Format("{0:n}", montoDolares)
                    </td>
                    <td class="vcenter">
                        @item.Cliente.Comision
                    </td>
                    <td class="vcenter">
                        @string.Format("{0:n}", comisionPagar)
                    </td>
                    <td style="text-align:center">
                        @Html.CheckBox("chkAutoriza", false, htmlAttributes: new { @class = "chkAutoriza", id= "chkAutoriza" + item.Pagos.IdPago })
                    </td>
                    <td style="text-align:center">
                        @Html.CheckBox("chkRechaza", false, htmlAttributes: new { @class = "chkRechaza", id = item.Pagos.IdPago })
                    </td>
                    <td class="vcenter">
                        @Html.TextBox("StudentName", null, new { @class = "form-control txtComentario", id = "txtComentario" + item.Pagos.IdPago })
                    </td>
                    <td id="[email protected]">
                        @item.Pagos.Fecha.ToString("dd/MM/yyyy")
                    </td>

                    <td class="vcenter text-right"></td>
                </tr>
            }
        </tbody>
    </table>

    <button class="btn btn-success" id="btnGuardar">Autorizar</button>

</div>
    
answered by 22.07.2018 в 08:09