Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC
In my view i have
 
@Html.TextBoxFor(per => per.Hospital, new { style = "width:220px", @maxlength = "50", data_autocomplete = Url.Action("HospitalList", "Person") })
 
My jquery is
 
$(document).ready(function () {        
    $('input[data_autocomplete]').each(function () {
        var url = $(this).data('autocomplete');
        $(this).autocomplete({
            source: function (request, response) {
                $.getJSON(url, {
                    term: request.term
                }, response);
            }
        });
    });
});
 
And a created a new Action result
 
public ActionResult HospitalList(string term)
    {
        List<string> result = new List<string>();
        result.Add("Hospital 1");
        result.Add("NYUMC");
        result.Add("Christ");
        result.Add("Bellevue");
        result.Add("NewYork-Presbyterian");
        result.Add("North Central Bronx Hospital");            
 
        return Json(result , JsonRequestBehavior.AllowGet);
    }  
now where am i going wromg. All I see a a text box , no behavior of auto complete. Should i be including any jquery library for it to work
Posted 5-Apr-13 10:39am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is because you have wrong autocomplete source, which is supposed to be an array, or a string or a function. In your case, the response function lacks return statement which is a main part defining the autocomplete data.
 
Please see: http://api.jqueryui.com/autocomplete/#option-source[^].
 
Pay attention for the sample "Using a custom source callback to match only the beginning of terms".
 
See also: http://api.jqueryui.com/autocomplete/[^].
 
—SA
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100