JQuery Autocomplete Plugin & .NET MVC


Reference :

http://docs.jquery.com/Plugins/Autocomplete

http://theycallmemrjames.blogspot.com/2010/03/jquery-autocomplete-with-aspnet-mvc.html

**************************************************************************

My HTML:

<%= Html.TextBox(“_officerAgency”, “”, new { id = “_officerAgency”, style= “Width = 200px;”})%>

My JS:

$(document).ready(function () {
$(“#_officerAgency”).autocomplete(‘<%= ViewData[“AgencyData”] %>’.split(“,”), { width: 200 });

});

My Controller

[Authorize]
public ActionResult Index(int? page)
{
ViewData[“AgencyData”] = LookupTagsForAgencies();

}

public string LookupTagsForAgencies()
{
string r = string.Empty;
List<string> tags = new List<string>();
using (IEnumerator<Agency> e = ListManager.GetAgenciesForAutoComplete().OfType<Agency>().GetEnumerator())
{
while (e.MoveNext())
tags.Add(e.Current.Name);
}
for (int i = 0; i < tags.Count; i++)
r += tags[i].ToString() + “,”;
return r;
}

Happy Coding. …. !!! 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s