ошибка автозаполнения пользовательского интерфейса jquery Uncaught TypeError: не удается прочитать свойство ‘0’ неопределенного

#javascript #c# #jquery #model-view-controller #autocomplete

#javascript #c# #jquery #model-view-controller #автозаполнение

Вопрос:

У меня есть эта ошибка, отображаемая в консоли:

 jquery-3.3.1.js:7972 Uncaught TypeError: Cannot read property '0' of undefined

at val (jquery-3.3.1.js:7972)
at add (jquery-3.3.1.js:8463)
at buildParams (jquery-3.3.1.js:8450)
at Function.jQuery.param (jquery-3.3.1.js:8483)
at Function.ajax (jquery-3.3.1.js:9073)
at $.<computed>.<computed>.source (Index:189353)
at $.<computed>.<computed>._search (VM12 jquery-ui-1.12.1.js:6015)
at $.<computed>.<computed>._search (VM12 jquery-ui-1.12.1.js:144)
at $.<computed>.<computed>.search (VM12 jquery-ui-1.12.1.js:6007)
at $.<computed>.<computed>.search (VM12 jquery-ui-1.12.1.js:144)
  

и оно отправляется, когда я начинаю печатать.

мой скрипт

 $('#pesticideTypeInput').autocomplete({
    source: function (request, response) {
        $.ajax({
            url: '@Url.Action("GetPesticideTypesList", "Search")',
            dataType: "json",
            data: { search: $('#pesticideTypeInput').val },
            success: function (data) {
                response($.map(data, function (item) {
                    //return { label: item.PesticideTypeAR, value: item.PesticideTypeAR };
                    return item;
                }));
            },
            error: function (xhr, status, error) {
                alert("Error");
            }
        });
    }
});
  

в моем контроллере у меня есть:

 public JsonResult GetPesticideTypesList(string term)
{
    var pesticidesTypesList = db.PesticideTypes.Where(x => x.PesticideTypeAR.Contains(term)).ToList();
    return new JsonResult {Data=pesticidesTypesList, JsonRequestBehavior=JsonRequestBehavior.AllowGet };
}
  

Мой класс модели:

 public partial class PesticideType
{
    public PesticideType()
    {
        this.PesticidesInfoes = new HashSet<PesticidesInfo>();
    }

    public int PesticideTypePk { get; set; }
    public string PesticideTypeAR { get; set; }
    
    public virtual ICollection<PesticidesInfo> PesticidesInfoes { get; set; }
}
  

Я ценю любую помощь, спасибо!

Комментарии:

1. Покажите нам структуру data полученного

2. Я отредактировал свой пост.

3. Это ваш серверный код…. что на самом деле получено в ajax success ?

4. Консольный отладчик показывает мне undefined, поэтому при успешном завершении не получены действительные данные

5. О … отсутствует () в search: $('#pesticideTypeInput').val … должно быть val()