【发布时间】:2019-05-29 18:40:39
【问题描述】:
我在这里使用 Jquery-ui AutoComplete 功能作为我的搜索框,但如果我搜索小写字母大写没有来到建议列表如何添加大写和小写敏感搜索此自动完成 Ajax ASP.net MVC
如果可能的话,添加匹配的文本粗体搜索建议列表?
查看页面
<input id="app-search">
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet" />
<script>
(function() {
$("#app-search").autocomplete({
minLength: 1, //start letter search
selectFirst: true,
autoFocus: true,
source: function(request, response) {
$.ajax({
url: '@Url.Action("GetSearchType")',
type: "POST",
dataType: "json",
data: {
SearchType: @Model.SearchType,
Prefix: request.term
},
success: function(data) {
if (!data.length) {
var result = [{
label: 'No record(s) found',
value: response.term
}];
response(result);
} else {
response($.map(data.slice(0, 10), function(item) {
return {
label: item.OrganizationName,
value: item.OrganizationName
};
}))
}
}
})
},
});
});
</script>
MVC Asp.net 中的这个控制器
[HttpPost]
public JsonResult GetSearchType(string Prefix)
{
List<OrganizationModel> OrganizationList = new List<OrganizationModel>()
{
new OrganizationModel {OrganizationName = "Apple" },
new OrganizationModel { OrganizationName = "name" },
new OrganizationModel { OrganizationName = "New" },
};
var CourseList = (from C in OrganizationList
where C.OrganizationName.StartsWith(Prefix)
select new { C.OrganizationName });
return Json(CourseList, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
标签: c# jquery linq jquery-ui asp.net-ajax