Autocomplete in ASP.NET MVC3自动检索并填充输入框
2023-09-11 14:19:21 时间
1、单一产品情况下使用:
public ActionResult GetStockList() { var item = _db.Stocks.ToList().Select(s =>s.Product.CodePro); return Json(item, JsonRequestBehavior.AllowGet); }
<script type="text/javascript"> $(function () { var url = "/Mana/BillOfLading/GetStockList"; $.getJSON(url, null, function (myData) { var availableTags = myData; $("#stockid").autocomplete({ source: availableTags }); }); }); </script> <div class="ui-widget"> <label for="stockid">Tags: </label> <input id="stockid" /> </div>
2、多组返回值的情况下:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script src="../../Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $("#SearchString").autocomplete({ source: "/Student/AutocompleteSuggestions", minLength: 1, select: function (event, ui) { if (ui.item) { $("#SearchString").val(ui.item.value); $("#txtlabel").text(ui.item.label); } } }); }); </script>
<div class="ui-widget"> <label id="txtlabel" style="color:Red"></label><br /> Find by name: @Html.TextBox("SearchString") <input type="submit" value="Search" /> </div>
public ActionResult AutocompleteSuggestions(string term) { var suggestions = db.Students.Select(s => new { label = s.LastName+"|"+s.FirstMidName, value = s.StudentID}).Where(b=>b.label.ToLower().StartsWith(term.ToLower())); return Json(suggestions, JsonRequestBehavior.AllowGet); }
相关文章
- ASP .NET CORE MVC 部署Windows 系统上 IIS具体步骤---.Net Core 部署到 IIS位系统中的步骤
- AngularJS2 + ASP.NET MVC项目
- asp.net发布后web.config里面的compilation的debug的值true和false有什么区别
- ASP.NET 最佳DataGrid读取单元格的值
- asp.net web api 跨域访问 OPTIONS 405
- Asp.net MVC模式实现登录功能
- asp.net中WebResponse 跨域访问示例
- asp.net url址址中中文汉字参数传递乱码解决方法
- asp .net 为图片添加图片水印 .
- 重新整理.net core 计1400篇[五] (.net core 修改为Startup模式 )
- [Tools] 一键让你的所有设备访问Google、youtube、facebook、twitter、battle.net
- [转] Asp.net 之 GC (垃圾回收机制)
- C# Protobuf-Net 序列化
- ASP.NET Core 6框架揭秘实例演示[10]:Options基本编程模式
- [ASP.NET Core 3框架揭秘] 配置[6]:多样化的配置源[上篇]
- .NET Core的文件系统[5]:扩展文件系统构建一个简易版“云盘”
- ASP.NET Core中的依赖注入(5): ServiceProvider实现揭秘 【总体设计 】
- 感恩回馈,新鲜出炉的《ASP.NET MVC 5框架揭秘》免费赠送
- ASP.NET Web Forms - 导航
- ASP.NET Web Forms - SortedList 对象
- HttpClient 调用WebAPI时—传参的三种方式(ASP.NET MVC&CORE均适用)
- ASP.NET Core微服务(六)——【redis命令详细列表1】
- ASP.NET—016:ASP.NET中保存文件对话框
- ASP.NET,C#后台调用前台javascript的五种方法
- Linux之bash: /proc/sys/net/ipv4/ip_forward: 权限不够
- ASP.NET Application_Error错误日志写入
- ASP.NET Core 6.0 添加 JWT 认证和授权
- ASP.NET Core 中间件的几种实现方式
- asp.net core NLog将日志写到文件
- Asp.Net Core 程序部署到Linux(centos)生产环境(二):docker部署
- DlhSoft Gantt Chart Web Library for ASP.NET
- ASP.NET Core微服务(六)——【redis命令详细列表1】
- ASP.NET Core微服务(六)——Redis效率与sqlserver数据库对比
- ASP.Net 内置对象