我试图将额外参数(所选值)传递给multiple select2
内的ajax调用:
$("#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
};
}
}
});
我实际上想要将另一个参数传递给ajax调用...以前选择的值..
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);
}
}
现在我的价值为null。