问题
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