How to edit data from a table in a modal bootstrap?

Asked

Viewed 259 times

1

How to load a modal bootstrap through a link within a tag < td > and send together column value Code, Name and Date example:

jquery:

$(document).on("click", "#lnkEditar", function () {
        $('#cadModal').modal('show');
    });

Modal

<div id="cadModal" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title">Segmento - Editar</h4>
            </div>
            <div class="modal-body" id="divEditarSegmento">
                @Html.Partial("_EditarSegmento", Model.Segmento)
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><i class="fa fa-close"></i> Fechar</button>
                <button type="button" class="btn btn-primary" id="btnLimparCamposSegmento"><i class="fa"></i> Limpar</button>
                <button type="button" class="btn btn-primary" id="btnGravarSegmento"><i class="fa fa-save"></i> Gravar</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

Partial

@model site.Entidade.Segmento
<form id="frmEditar">

                <div class="row">
                    @Html.HiddenFor(model => model.Codigo)
                    <div class="col-md-12">
                        @Html.LabelFor(model => model.codigo)
                        @Html.TextBoxFor(model => model.codigo, new { @class = "form-control" })
                    </div>

                </div>
                <div class="row">
                     <div class="col-md-2">
                        @Html.LabelFor(model => model.Nome)
                        @Html.TextBoxFor(model => model.Nome, new { @class = "form-control" })
                    </div>
                    <div class="col-md-2">
                        @Html.LabelFor(model => model.Data)
                        @Html.TextBoxFor(model => model.Data, new { @class = "form-control" })
                    </div>

    </div>

table html:

<tbody>
    for (int i = 0; i < Model.Segmentos.Count; i++)
            {
            <tr>
                <td><a href="#" id="lnkEditar" name="lnkEditar" class="btn btn-primary btn-xs btn-social-icon"><i class="fa fa-pencil"></i></a></td>
                <td>@Model.Segmentos[i].Codigo</td>
        <td>@Model.Segmentos[i].Nome</td>
                <td">@Model.Segmentos[i].Data</td>
            </tr>
            }
    </tbody>
  • Also include the partial in the question _EditarSegmento

  • @Isac added Partial in the post

  • The goal is to show the data in the modal when it is clicked ? In textboxes that comes from partial ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.