【发布时间】:2019-10-24 12:46:37
【问题描述】:
我正在使用它进行渐进式搜索。
从技术上讲,它可以工作,但控件没有被返回的数据填充。
$("#selUser").select2({
ajax: {
url: "/M01EngineeringData/GetFunctionalLocations",
type: "GET",
dataType: 'json',
delay: 250,
data: function (params) {
return {
search: params.term // search term
};
},
processResults: function (response) {
// alert(response);
return {
results: response
};
},
cache: true
}
});
HTML:
<div class="col-md-4 col-sm-12">
<div class="col-md-5">
<span class="Label_small_bold">Progressive Search :</span>
</div>
<div class="col-md-7">
<select id='selUser' style='width: 200px;'>
<option value='0'>- Search user -</option>
</select>
</div>
</div>
控制器:
public JsonResult GetFunctionalLocations(string search)
{
try
{
return Json(enggDataService.GetFunctionalLocations(search) , JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw;
}
}
这个控制器正在以正确的格式返回数据。
["Test Func Location","Test Func Location","Test Func Location"]
但是 selUser 控件没有填充数据,为什么?
【问题讨论】:
标签: jquery asp.net json ajax asp.net-mvc