Les*_*s P 5 jquery autocomplete asp.net-core
我正在使用带有Boostrap 4的ASP.NET核心jquery自动完成功能我已成功运行以下示例:https://jqueryui.com/autocomplete/
我现在正在寻找使用我的控制器中的数据来正确返回数据.我得到的结果是空行.
这是我的剃刀页面
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="ui-widget">
<label>Autocomplete Example: </label>
<input id="LastName" name="LastName" type="text" />
</div>
<script>
$("#LastName").autocomplete({
source: '@Url.Action("GetName","Home")'
});
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器[HttpGet] public IActionResult GetName(string term){
List<TransactionName> list = new List<TransactionName>()
{
new TransactionName {Id=1,LastName="Linda" },
new TransactionName {Id=2,LastName="Donna" },
new TransactionName {Id=3,LastName="Maryanne" },
new TransactionName {Id=4,LastName="Deb" },
new TransactionName {Id=5,LastName="Liz" },
new TransactionName {Id=6,LastName="Bobby" },
new TransactionName {Id=7,LastName="Beth" }
};
var result = (from N in list
where N.LastName.Contains(term)
select new {N.LastName });
return Json(result);
}
Run Code Online (Sandbox Code Playgroud)
我根据 jquery 自动完成文档更改了以下内容:
var result = (from N in list
where N.LastName.Contains(term)
select new {value=N.LastName });
Run Code Online (Sandbox Code Playgroud)
这是从他们的网站上获取的部分文档。支持多种类型: 数组:可以使用数组来存储本地数据。支持两种格式: 字符串数组:[ "Choice1", "Choice2" ] 具有标签和值属性的对象数组:[ { label: "Choice1", value: "value1" }, ... ]
| 归档时间: |
|
| 查看次数: |
3627 次 |
| 最近记录: |