我为 Jquery Auto 完成了很多研发工作,我找到了一些结果,但没有我需要的那么多。我给你的代码是我目前正在使用的。
<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”的静态值,我正在删除前两个字符以从数据库中进行正确搜索。谢谢