passing selected value to jQuery's select2 ajax call

纵然是瞬间 提交于 2020-01-07 03:04:40

问题


I'm attempting to pass an extra parameter(the selected value) to an ajax call within multiple select2:

 $("#ddlMultiCourse").select2({
    placeholder: "Search for Course",
    minimumInputLength: 1,
    allowClear: true,
    ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
        url: url,//GetCourseList
        type: "POST",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                term: params.term, // search term
                value: $("#ddlMultiCourse").val()//extra parameter
            };
        },
        processResults: function (data, params) {              

            return {
                results: data

            };
        }

    }
});

I actually want to pass another parameter to the ajax call... the previously selected values..

 public JsonResult GetCourseList(string term, string[] value)
    {
        try
        {

            var _courseList = _db.MultiCourses
                            .Where(x => x.CourseCode.StartsWith(term))
                            .Select(x => new 
                            {
                                id=x.Id,
                                text=x.CourseCode
                            }).ToList();


            return Json(_courseList, JsonRequestBehavior.AllowGet);

        }
        catch (Exception ex)
        {
            return Json("", JsonRequestBehavior.AllowGet);
        }
    }

Now I am getting value as null.

来源:https://stackoverflow.com/questions/34217828/passing-selected-value-to-jquerys-select2-ajax-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!