此功能无效请帮助我,我需要在建议的文本框中自动完成数据
$('#BrandName').autocomplete({
source: function (request, response) {
$.getJSON("/DataCollection/SuggestBrandName?term=" + request.term, function (data) {
response(data);
});
},
minLength: 1,
delay: 100
});
我的json结果
public JsonResult SuggestProduct(string term)
{
var DataBase = new DataBaseEntities();
var allProduct = DataBase.Tbltables.Select(s => s.BrandName).ToList();
var getAutocomplete = allProduct.Where(item => item.ToUpper().StartsWith(term.ToUpper())).Distinct().ToList();
DataBase.Dispose();
return Json(getAutocomplete, JsonRequestBehavior.AllowGet);
}
答案 0 :(得分:1)
试用此代码:
$('#BrandName').autocomplete({
source: function (request, response) {
$.ajax({
url: "@Url.Content("~")/DataCollection/SuggestBrandName",
data: { term : request.term },
success: function (data) {
response(data);
}
});
},
minLength: 1,
delay: 100
});