您可以使用jQuery UI autocomplete
插件。基本上你需要設置一個控制器動作,它將被AJAX調用,它將作爲用戶在文本框中輸入的參數term
傳遞。此控制器操作應該以JSON結果返回插件將顯示的建議列表。
例如:
public ActionResult Suggest(string term)
{
// TODO: use the term here to query your data source
// and return the suggested results as JSON:
var results = new[]
{
new { id = "1", label = "label 1", value = "value 1" },
new { id = "2", label = "label 2", value = "value 2" },
new { id = "3", label = "label 3", value = "value 3" },
};
return Json(results, JsonRequestBehavior.AllowGet);
}
和客戶端上附接插件文本框:
<script type="text/javascript">
$(function() {
$('#SearchBox').autocomplete({
source: '@Url.Action("Suggest")',
minLength: 3,
select: function (evt, ui) {
}
});
});
</script>
使用jQuery自動填充 – Nilesh
http://www.codeproject.com/Articles/42490/Using -AvalonEdit-WPF-Text-Editor還有一個關於如何實現智能感知功能的很好的教程。 – Eisenhorn