AutoComplete Text in MVC using Jquery

Madhu.B.Rokkam
Posted by Madhu.B.Rokkam under ASP.NET category on | Points: 40 | Views : 1686
Controller Code
**************************
public ActionResult Index()
{
ViewBag.SampleItems= new string[] {"Apple", "Airplane", "Asp", "Ball", "Cat", "Cook"};
return View();
}


View Code
*********************

<script>

$(function () {
var sampleItems = new Array();
var array = @Html.Raw(Json.Encode(@ViewBag.SampleItems));
for(var i =0; i<array.length;i++)
sampleItems[i] = array[i];
$("#items").autocomplete({ source: sampleItems });
});

</script>

<p>
AutoComplete field: <input id="items" />
</p>

Comments or Responses

Login to post response