Pass the Dropdownlistfor value through a @Url.Action

Asked

Viewed 187 times

1

How to pass the value of @Html.DropDownListFor selected by a @Url.Action ?, example:

<div class="row">
        <div class="col-xs-4">
            <label>Cliente</label><br />
            @Html.DropDownListFor(x => x.Atendimento.ClienteID, (IEnumerable<SelectListItem>)ViewBag.Clientes, "[Selecione]", new { @class = "form-control" })
        </div>

        <div class="col-xs-4" id="divPaciente">
            <label>Paciente</label><br />
            @Html.DropDownListFor(x => x.Atendimento.PacienteID, (IEnumerable<SelectListItem>)ViewBag.Pacientes, "[Selecione]", new { @class = "form-control" })
        </div>

        <div class="col-xs-1">
            <label><br /></label><br />
            <a href="@Url.Action("Incluir", "Paciente", new { ClienteID = "**Como informar o valor do DropDownListFor**"})" style="text-decoration: none;" title="Incluir Paciente" ><span class="fui-plus-circle" style="font-size: 22px;"></span></a>
        </div>
    </div>

1 answer

2


By Javascript.

Change your link to have the following:

<a id="MeuLink" style="text-decoration: none;" title="Incluir Paciente"><span class="fui-plus-circle" style="font-size: 22px;"></span></a>

Open a @section Scripts in View:

@section Scripts {
    <script>
        jQuery(document).ready(function () {
            $(document).on("click", "#MeuLink", function () {
                window.location = "@Url.Action("Incluir", "Paciente")/" + $("#PacienteID").val();
            });
        });
    </script>
}

Browser other questions tagged

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