Click here to Skip to main content
15,889,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
textbox autocomplet not showing any data.
my json request called and data also return but not show on textbox dropdown.
code:
JavaScript
<script type="text/javascript">
    $(document).ready(function () {
        $('#txtJobSkill2').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/Jobs/SkillAutoComplete",
                    type: "POST",
                    dataType: "json",
                    data: { term: request.term },
                    success: function (data) {
                        alert(data);
                        response($.map(data, function (item) {
                            alert(item);
                          
                            return { label: item, value: item };
                        }))


                    }
                })
            },
            messages: {
                noResults: "", results: ""
            }
        });
    })
</script>

C#
public JsonResult SkillAutoComplete(string term)
        {
            //List<string> skills = new List<string>();
            var context=mydatacontext;

              var  skills = (from a in context.Masterdata
                          where a.Description.StartsWith(term)
                                select a.Description).Distinct().ToList();
                return Json(skills.Distinct(), JsonRequestBehavior.AllowGet);

            //return Json(skills, JsonRequestBehavior.AllowGet);
        }
Posted
Updated 25-Nov-14 0:34am
v4

1 solution

$(function () {
    $('#DRMCompanyId').autocomplete({
        source: function (request, response) {
           $.ajax({
               url: '@Url.Action("compSearch", "AgentTransmission")',
               type: 'GET',
               dataType: 'json',
               data: request,
               success: function (data) {
                   response($.map(data, function (value, key) { 
                        return {
                            label: value,
                            value: key
                        };
                   }));
               }
           });
        },
        minLength: 2
    });

});

Refer this link for more
http://stackoverflow.com/questions/16219026/jquery-use-key-value-pair-in-autocomplete[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900