Question

This function is not working please help me i need to auto complete the data in suggested text box

 $('#BrandName').autocomplete({
        source: function (request, response) {
            $.getJSON("/DataCollection/SuggestBrandName?term=" + request.term, function (data) {
                response(data);
            });
        },
        minLength: 1,
        delay: 100
    });

my json result

  public JsonResult SuggestProduct(string term)
    {
        var DataBase = new DataBaseEntities();
        var allProduct = DataBase.Tbltables.Select(s => s.BrandName).ToList();            
        var getAutocomplete = allProduct.Where(item => item.ToUpper().StartsWith(term.ToUpper())).Distinct().ToList();            
        DataBase.Dispose();
        return Json(getAutocomplete, JsonRequestBehavior.AllowGet);
    }
Was it helpful?

Solution

Try This Code:

$('#BrandName').autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "@Url.Content("~")/DataCollection/SuggestBrandName",
            data: { term : request.term },
            success: function (data) {
                response(data);
            }
        });
    },
    minLength: 1,
    delay: 100
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top