zoukankan      html  css  js  c++  java
  • Autocomplete in ASP.NET MVC3自动检索并填充输入框

    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);
    }
  • 相关阅读:
    iOS_UIImage的方向(imageOrientation)
    iOS-LaunchImage启动页
    iOS_UIImage_毛玻璃效果
    iOS_常用C语言函数
    iOS_UIImage_Gif的合成
    iOS_UIImage_Gif的分解
    iOS_UIImge_Gif的展示
    iOS_UIImage_jpg<-->png转换
    Mysql学习第三天
    Mysql学习第二天
  • 原文地址:https://www.cnblogs.com/firstcsharp/p/3214641.html
Copyright © 2011-2022 走看看