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

teething problems

0 Answers 61 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 18 Jan 2013, 04:52 PM
Ive just started using AutoComplete and Im having a few problems, basically nothing shows up when I start typing in the box, hopefully someone might be able to give me a few pointers.

in my controller (AccountController)  I have this method

[HttpGet]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public JsonResult GetCountries()
        {
            RegisterModel model = new RegisterModel();
            return Json(model.Countries, JsonRequestBehavior.AllowGet);
        }

in my model (AccountModel)  I have this property and method

public IEnumerable<EbsData.TimeZone> Countries { get {return GetCountries();} set{value = GetCountries();} }


/// <summary>
        /// get all the current countries from cache or repository
        /// </summary>
        /// <returns></returns>
        private IEnumerable<EbsData.TimeZone> GetCountries()
        {
            Service.InMemoryCache cacheProvider = new Service.InMemoryCache();
            using (var context = new EbsData.EBSEntities())
            {
                var countries = cacheProvider.Get("countries", () => (from c in context.TimeZones select c).ToList());
                return countries;
            }

        }

and in my view, I have this markup


<li>
                @Html.LabelFor(m => m.Country)
                @Html.Kendo().AutoCompleteFor(m => m.Country).Name("countriesAutoComplete").Animation(true).IgnoreCase(true).DataTextField("Country").DataSource(source =>
                                                                                                                                                         {
                                                                                                                                                                source.Read(read =>
                                                                                                                                                                {
                                                                                                                                                                    read.Action("GetCountries", "AccountController").Data("onAdditionalData"); //Set the Action and Controller name
                                                                                                                                                                })
                                                                                                                                                                .ServerFiltering(true); //If true the DataSource will not filter the data on the client.
                                                                                                                                                         })                                                                                                                                                     

            </li>


which creates this hmtl

<li>
<label for="Country">Country</label>
<span class="k-widget k-autocomplete k-header k-state-default" tabindex="-1" role="presentation" style="">
<input id="countriesAutoComplete" class="k-input" type="text" name="countriesAutoComplete" data-val-required="The Country field is required." data-val="true" data-role="autocomplete" style="width: 100%;" autocomplete="off" role="textbox" aria-haspopup="true" aria-disabled="false" aria-owns="countriesAutoComplete_listbox" aria-autocomplete="list">
</span>
<script>
jQuery(function(){jQuery("#countriesAutoComplete").kendoAutoComplete({"dataSource":{"transport":{"read":{"url":"/AccountController/GetCountries","data":onAdditionalData}},"serverFiltering":true,"filter":[],"schema":{"errors":"Errors"}},"dataTextField":"Country","ignoreCase":true});});
</script>
</li>


there is data available for the autocomplete to use, and the javascript function is there, but none of the server code is being executed.  Can anyone see where Im going wrong ?




No answers yet. Maybe you can help?

Tags
AutoComplete
Asked by
mww
Top achievements
Rank 1
Share this question
or