Pass a view’s value to modal

Asked

Viewed 74 times

-1

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

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

to open the modal is like this:

$(document).ready(function () {
    $.ajaxSetup({ cache: false });
    $(".btnCreate").click(function () {
        $("#modal").load("/Trabalhos/Create/", function () {
            $('#myModal').modal("show");
        });
    });
});
  • Please insert the modal html code.

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>
}

Browser other questions tagged

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