Click here to Skip to main content
11,796,774 members (80,902 online)
Rate this: bad
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');
            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("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 9:39am

1 solution

Rate this: bad
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:[^].

Pay attention for the sample "Using a custom source callback to match only the beginning of terms".

See also:[^].


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

  Print Answers RSS
0 Abhinav S 379
1 OriginalGriff 360
2 Maciej Los 360
3 CPallini 295
4 KrunalRohit 280
0 OriginalGriff 2,032
1 Maciej Los 1,725
2 KrunalRohit 1,310
3 CPallini 1,055
4 ppolymorphe 883

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2015
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