Jqueryオートコンプリートの研究開発をたくさん行ったので、いくつかの結果が見つかりましたが、必要なほどではありませんでした。現在使用しているコードを提供しています。
<ul>
@foreach (var items in Model)
{
<li class="@items.ShortDesc" id="@items.ShortDesc">
<div class="test0">
@Html.TextBox(@items.ShortDesc, @items.SfldDefault, new { @class = "catalog inputcatalog txtbox" })
</div>
</li>
}
</ul> This input box will created by Dynamic using forloop
//私のJqueryコード
$(function () {
$("#Subject").autocomplete({
source: '/Cataloging/Bib/GetSubject',
minLength: 1,
select: function (event, ui) {
// Do something with "ui.item.Id" or "ui.item.Name" or any of the other properties you selected to return from the action
}
});
});
//私のアクションメソッド
public ActionResult GetSubject(string term)
{
term = term.Substring(2, term.Length-2);
return Json(db.BibContents.Where(city => city.Value.StartsWith(term)).Select(city => city.Value), JsonRequestBehavior.AllowGet);
}
//コードは静的入力で実行されていますが、動的を作成するときにライブイベントを使用する必要がありますが、このコードでライブイベントを使用する方法がわかりません。
注:アクションでレンダリングした後、入力 "| a"の静的な値を使用しています。データベースから適切な検索を行うために、最初の2文字を削除しています。ありがとう