I need to do something like this: Jquery Autocomplete
jQuery:
$("#NumeroContrato").autocomplete({
source: function (request, response) {
$.ajax({
type: 'GET',
url: 'Cliente/ListarClientePorContratoJSON',
dataType: 'jsonp',
crossDomain: true,
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Nome,
id: item.ClienteID
}
}))
},
});
},
minLength: 1,
select: function (event, ui) {
$("#NumeroContrato").val(ui.item.label);
$("#ClienteID").val(ui.item.id);
alert(ui.item.id);
event.preventDefault();
}
});
HTML:
<input type="hidden" id="ClienteID" name="ClienteID">
<div class="col-xs-2">
<label>Num. Contrato</label><br />
<input type="text" id="NumeroContrato" name="NumeroContrato" value="" class="form-control" />
</div>
Controller:
public JsonResult ListarClientePorContratoJSON(string NumeroContrato)
{
try
{
//AQUI VOU FAZER A CHAMADA PARA PESQUISA DO NUMERO DO CONTRATO:
}
catch (Exception)
{
return Json("erro", JsonRequestBehavior.AllowGet);
}
}
Problem:
The problem is that the Numero Contratrato variable is always equal to Null