Autocomplete does not show results in input in View

4

I've seen other cases in some answers here, tried to follow in the footsteps of other answers and it did not help at all! I'm having a question, this is my first time using autocomplete of jquery , I'm new to asp.net mvc !

I wanted the user to type in textbox or input , from waking up with him typing already appeared the result of what he is looking for in the field, which led me to autocomplete, followed a few steps on the internet, but how it's my first time using it, I'm in doubt, it does not return bank data, because what I want to return from the bank is the CLIENT by IDCLIENT , the < strong> SQL I already have! My problem and that it is not bringing when typing does not appear anything!

  

This is my View with the Jquery function at the top 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>

I am trying to use this autocomplete in the last line of code with% Client and%

My Jquery function is in the first row, there in the beginning! With GetClientsJson

  

My id and the elemento html of this td and the ControllerVendasPorProduto that returns the data to this Action looks like this: p>

        [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 out there is not returning me the data in the field, nor showing the names of Clients as user type! It does not return anything to me, as I said the first time I use this View . Could you tell me what is wrong and would like a code solution based on what I showed!

    
asked by anonymous 20.01.2015 / 14:48

1 answer

0

It seems like a bit, but try removing the "," after action

$("#cliente").autocomplete({
    source: '@Url.Action("GetClientesJson",)',
    minLength: 1
});

And you're sure you've added jquery-ui to the library for autocomplete? And, [HttpPost] should not be added to the method, since you are not specifying to be via Post , since deafult is Get .

If it still does not work, mount JSON on hand and add it to Source . So you have a starting point to understand where the error is, on the server or the client.

    
09.03.2015 / 21:32