Pass the value of the DropDownListFor through an @ Url.Action

1

How to pass the value of the @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>
    
asked by anonymous 26.02.2016 / 17:00

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>
}
    
26.02.2016 / 17:13