开发者

JQuery UI Autocomplete and Generic Handler (ashx) - C# ASP.NET

I'm trying to use the JQuery Autocomplete, but I guess I am having trouble getting the format it expects from my handler.

Here is what the handler does. This was in another SO question....

 context.Response.ContentType = "text/plain";
 var companies = GetCompanies(); //This returns a list of companies (List<string>)

 foreach (var comp in companies)
 {
     context.Response.Write(comp + Environment.NewLine);
 }

This doesn't work. It is definately getting called and it is returni开发者_如何学Pythonng what I would expect this code to return. Any ideas?


It needs to be in JSON format indeed, here a sample of the general outline I used before:

    class AutoCompleteEntry
    {
        public int id { get; set; }
        public string label { get; set; }
        public string value { get; set; }
    }

    private void GetAutoCompleteTerms()
    {
        Response.Clear();
        Response.ContentType = "application/json";

        //evaluate input parameters of jquery request here

         List<AutoCompleteEntry> autoCompleteList= new List<AutoCompleteEntry>();
        //populate List of AutocompleteEntry here accordingly

        JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
        string json = jsSerializer.Serialize(autoCompleteList);
        Response.Write(json);
        Response.End();
    }


The response needs to be in JSON format. See http://docs.jquery.com/UI/Autocomplete where it discusses using a String that specifies a URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜