This is a migrated thread and some comments may be shown as answers.

AJAX AutoComplete not displaying the items

3 Answers 163 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 05 Nov 2012, 05:14 PM

Hi. I just want to display a list of values that are retrieved serverside using AJAX.  It calls the AJAX method successfully, but does not display the returned values.

Markup:

      @(Html.Kendo().AutoComplete()
.Name("EditNameAutoComplete")
.DataSource(source =>
            source.Read(read => read.Action("GetUsers", "Administration"))
                .ServerFiltering(true)))

Method:

public JsonResult GetUsers()
{
    string input = Request.Params["filter[filters][0][value]"];
    var adValues = //Get names from Active Directory that start with our input
    var users = adValues.Select(user => user.CommonName).ToList();
    users.Sort();
    return Json(users);
}

Should be simple enough, and it's calling the Ajax method, but not displaying anything afterward. It just acts like a normal textbox. I'm definitely returning strings. What am I doing wrong?

3 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 05 Nov 2012, 05:51 PM
Disregard, I figured it out. I should have been specifying AllowGet for the JSON, like so:

return Json(users, JsonRequestBehavior.AllowGet);

Woohoo!
0
Dave
Top achievements
Rank 1
answered on 05 Nov 2012, 06:38 PM
New question - is there a way to set up Kendo AutoComplete to perform a POST instead of a GET, using the MVC extensions?
Thanks.
0
Dave
Top achievements
Rank 1
answered on 16 Nov 2012, 04:50 PM

Aha, found it.

@(Html.Kendo().AutoCompleteFor(m => m.NewIssue.Responsible)
      .MinLength(3)
      .HtmlAttributes(new { @class="autocomplete" })
        
      .DataSource(ds => ds.Read(r => r.Action("GetUserNames", "Ajax").Type(HttpVerbs.Post))
                          .ServerFiltering(true)))
Tags
AutoComplete
Asked by
Dave
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Share this question
or