Select2 drop down not producing results

Viewed 22

I'm using Select2 3.x in an MVC C# build. I'm 99% certain we're getting a JSON object delivered to the page. But it's producing nothing. No alerts. Can't get a console event. Nothing.

Screen shot of result

Here's the JS:

    $('#component-ajax').select2({
    minimumInputLength: 2,
    ajax: {
        url: '@Url.Action("AjaxComponents")',
        dataType: 'json',
        type: "GET",
        delay: 250, // wait 250 milliseconds before triggering the request
        data: function (params) {
            var query = {
                search: params
                //,page: page
            }
            return query;
        }
        , results: function (obj, page) {
            alert('hi');
            
            
            return {results: obj};
        }
    },
    placeholder: 'Component number'
});

The "HTML":

                        <div class="form-group">
                        <label class="control-label col-sm-3">Item Number</label>
                        <div class="col-sm-9">
                            @Html.HiddenFor(m => m.NewProductBOMComponent.ItemKey, new { @class = "js-data-component-ajax form-control", placeholder = "Search for customer", id = "component-ajax" })
                        </div>
                    </div>

The Controller:

        public ContentResult AjaxComponents(string search)
    {
        var json = Services.FourthShiftItemService.FindComponents_jqs2(search);

        return Content(json, "application/json");

    }

And a JSON sample:

{"results":[{17825:"550-02"},{6495:"550-11"}],"pagination":{"more":false}}
0 Answers
Related