1, label
<input type= "text" data-autocomplete-source= "@Url. Action (" QuickSearch "," Demo ")"/>
2, you need to reference styles and scripts
<link href= "@Url. Content (" ~/content/themes/base/jquery.ui.all.css ")" rel= "Stylesheet" type= "Text/css"/>
<script type= "Text/javascript" src= "@Url. Content (" ~/scripts/jquery-ui-1.8.11.min.js ")" ></script>
3, script code
<script type= "Text/javascript" >
$ (function () {
$ ("Input[data-autocomplete-source]"). each (function () {
$ (this). AutoComplete ({Source: $ (this). attr ("Data-autocomplete-source")});
});
});
</script>
4, Controller code
Public Jsonresult QuickSearch (string term)
{
var s = db. Demos.where (r = r.name.contains (term)). ToList (). Select (A = new {value = A.name});
A GET request from the client must be allowed. But there's a security risk.
Return Json (S, jsonrequestbehavior.allowget);
}
This article is from the "program Ape's Home--hunter" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1612488
MVC3----JQuery UI Auto-complete widgets