Pass value from a view to modal

-1

Starting my studies in MVC I am doing a CD registration. It turns out I have a view with artist details (Artists / Details / 1). In this View, I have a "New" button to type a new artist CD and it opens a modal window for it (Jobs / Create). You would need to "pass" the name of the artist that is in Artists / Details / 1 to this modal. How is this possible? The button code looks like this:

<a href="#" class="btn btn-info btnCreate" style="width: 220px; background-color:darkseagreen">Novo</a>

To open the modal it looks like this:

$(document).ready(function () {
    $.ajaxSetup({ cache: false });
    $(".btnCreate").click(function () {
        $("#modal").load("/Trabalhos/Create/", function () {
            $('#myModal').modal("show");
        });
    });
});
    
asked by anonymous 24.04.2018 / 14:19

1 answer

0

Well, the modal will open the Create view:

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <table style="margin:auto">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <tr>
            <td>
                @Html.LabelFor(model => model.Descricao, htmlAttributes: new { @class = "control-label col-md-2" })
            </td>
            <td>
                @Html.EditorFor(model => model.Descricao, new { htmlAttributes = new { @class = "form-control", autofocus = true } })
                @Html.ValidationMessageFor(model => model.Descricao, "", new { @class = "text-danger" })
            </td>
        </tr>
    </table>

    <table style="margin:auto">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <tr>
            <td>
                @Html.LabelFor(model => model.Ano, htmlAttributes: new { @class = "control-label col-md-2" })
            </td>
            <td>
                @Html.EditorFor(model => model.Ano, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Ano, "", new { @class = "text-danger" })
            </td>
        </tr>
    </table>

    <table style="margin:auto">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <tr>
            <td>
                @Html.LabelFor(model => model.Artista, htmlAttributes: new { @class = "control-label col-md-2" })
            </td>
            <td>
                **AQUI É QUE MOSTRARIA O NOME DO ARTISTA**
            </td>
        </tr>
    </table>

    <br />
    <hr />

    <table style="margin:auto;">
        <tr>
            <td>
                <input type="submit" value="Confirma inclusão" class="btn btn-success" />
            </td>
            <td>
                <a href="#" class="btn btn-danger btnBack">Cancela</a>
            </td>
        </tr>
    </table>
}
    
24.04.2018 / 15:18