4
I have seen other cases in some answers here, I tried to follow the steps of other answers and did not help at all! I’m having a doubt, this is my first time using autocomplete
of jquery
, I’m new in Asp.net mvc!
I wanted the user to type in textbox
or input
, waking up with him typing already appeared the result of what he is looking for in the field, which led me to the autocomplete, followed a few steps on the internet, but as it is my first time using it, I’m doubtful, it does not return the database data, because what I want to return from the bank is the CLIENT for IDCLIENTE, the instruction SQL I already have!
My problem and what he is not bringing when typing does not appear anything!
This is my
View
with the function Jquery at the beginning of the page:
<script>
$(function () {
$("#cliente").autocomplete({
source: '@Url.Action("GetClientesJson",)',
minLength: 1
});
});
</script>
<div class="row">
<div class="span12">
<div class="widget widget-table action-table">
<div class="widget-header">
<i class="icon-th-list"></i>
<h3>Vendas Por Produtos</h3>
</div>
<!-- /widget-header -->
<div class="widget-content">
@if (ViewData["reportvendas"] == null)
{
<form action="#" id="myform" method="post">
<div class="login-fields">
<div class="field">
<table style="margin:10px">
<tr>
<td>Data Venda:</td>
<td><input type="text" id="inicio" name="inicio" class="login requerido birth" style="width:90px" /></td>
<td>Ate</td>
<td><input type="text" id="fim" name="fim" class="login requerido birth" style="width:90px" /></td>
<td>Agrupado</td>
<td>
<select id="agrupamento" name="agrupamento" class="login" style="width:200px">
<option value="grupo">Grupo</option>
<option value="vendedor">Vendedor</option>
<option value="cliente">Cliente</option>
</select>
</td>
</tr>
<tr>
<td>Grupo:</td>
<td>
<select id="grupo" name="grupo" class="login" style="width:200px">
<option value="">Selecione</option>
@foreach (var item in combo.Grupo().OrderBy(ordem => ordem.DESCRICAO))
{
<option value="@item.IDPRODGRUPO">@item.DESCRICAO</option>
}
</select>
</td>
<td>Sub Grupo:</td>
<td>
<select id="subgrupo" name="subgrupo" class="login" style="width:200px">
<option value="">Selecione</option>
@foreach (var item in combo.SubGrupo().OrderBy(ordem2 => ordem2.DESCRICAO))
{
<option value="@item.IDSUBGRUPO">@item.DESCRICAO</option>
}
</select>
</td>
<td>Fabricante:</td>
<td>
<select id="fabricante" name="fabricante" class="login" style="width:200px">
<option value="">Selecione</option>
@foreach (var item in combo.Fabricante().OrderBy(m => m.NOMERAZAO))
{
<option value="@item.IDFABRICANTE">@item.NOMERAZAO</option>
}
</select>
</td>
</tr>
<tr>
<td>Codigo de Barras</td>
<td><input type="text" id="codigoinicio" name="codigoinicio" class="login" style="width:90px" /></td>
<td>a</td>
<td><input type="text" id="codigofim" name="codigofim" class="login" style="width:90px" /></td>
</tr>
<tr>
<td>Cliente:</td>
<td>
@using (Html.BeginForm())
{
@Html.TextBox("dados", null, new { id = "cliente" });
<input type="submit" value="Procurar" />
}
</td>
Where I’m trying to use this autocomplete is on the last line of code with id
Client and the elemento html
td
Client
My Jquery function is on the first line, there at the beginning ! With Getclientesjson
My
ControllerVendasPorProduto
and theAction
of thisView
and theJsonResult
which returns the data to thisView
is like this:
[HttpPost]
public ActionResult Movimentacao_Total_Vendas(ReportsMovimentacaoTotalVendas dados)
{
ReportsData report = new ReportsData();
report.MovimentacaoTotalVendas(dados);
return View();
}
[HttpPost]
public JsonResult GetClientesJson(string term)
{
ComboData BDGetClientesJson = new ComboData();
List<string> nomes;
nomes = BDGetClientesJson.Cliente().Where(x => x.CLIENTE.StartsWith(term)).Select(c => c.CLIENTE).ToList();
return Json(nomes,JsonRequestBehavior.AllowGet);
}
Well, with all this following a few steps around it is not returning me the data in the field, nor showing the names of Customers as user type! Nothing returns to me, as I said first time I use this autocomplete
. Could you tell me what’s wrong and I would like a code solution based on what I’ve shown !
Is the request coming to the controller? Have you tried removing HTTPPOST from the action header?
– PauloHDSousa
@Paulohdsousa just took the HTTPOST and nothing!
– Raffa Ferreira
The requisitions are not coming right?
– PauloHDSousa
Right, exactly!!
– Raffa Ferreira
Okay, could you look at the browser network and see if the request is 404?
– PauloHDSousa
It’s on, Get 200 -OK and Post 200 OK !
– Raffa Ferreira
If you are giving 200 how can they not be getting into the API?
– PauloHDSousa
I also do not know, the code is the way I put there in this post!
– Raffa Ferreira
If you access via
url
you return this data?– Randrade