How to get the selected item from the DropDownList Select2 plugin ( link ), and send it to a Controller through a button submit?
CONTROLER
publicActionResultIndex(ContratoViewModelcontratoViewModel){intid=contratoViewModel.Id;}
SUBMITBUTTON
<inputclass="btn btn-primary" value="Buscar" type="submit" id="btnBuscar" />
HTML
@using(Html.BeginForm("Index", "Contrato", FormMethod.Get))
{
<div class="row">
<div class="col-xs-3">
<label>Cliente</label><br />
<select id="ClienteID" name="ClienteID" class="form-control">
<option value="0">[SELECIONE]</option>
</select>
</div>
<div class="col-xs-3">
@Html.LabelFor(x => x.ContratoViewModel.NumeroContrato)
@Html.TextBoxFor(x => x.ContratoViewModel.NumeroContrato, new { @class = "form-control" })
</div>
<div class="col-xs-3">
@Html.LabelFor(x => x.ContratoViewModel.Responsavel)
@Html.TextBoxFor(x => x.ContratoViewModel.Responsavel, new { @class = "form-control" })
</div>
<div class="col-xs-2">
@Html.LabelFor(x => x.ContratoViewModel.Status)<br />
@Html.RadioButtonFor(x => x.ContratoViewModel.Status, "true", new { @checked = "checked" }) Ativo
@Html.RadioButtonFor(x => x.ContratoViewModel.Status, "false") Inativo
</div>
}
JAVASCRIPT
<script src="~/Content/Scripts/select2.full.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#ClienteID").select2({
allowClear: true,
ajax: {
type: 'GET',
url: '/Contrato/ListarClienteJSON',
data: function (params) {
return {
pNome: params.term
};
},
dataType: 'json',
processResults: function (data) {
return {
results: data
};
}
}
});
});
</script>