This solution uses WebService, Entity Framework , Jquery, JqueryUI
View Page
<html lang="en">
<head>
<title>jQuery UI Autocomplete</title>
<link rel="stylesheet"
href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")">
<script src="@Url.Content("~/Scripts/jquery-1.5.2.min.js")"
type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.16.min.js")"
type="text/javascript"></script>
<script
$(function () {
$("#txtSiteName").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebService1.asmx/GetAllSites",
data: "{'keywords':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data) {
response(data.d);
},
error: function (result) {
//alert("Error");
}
});
}
});
});
</script>
</head>
<body>
<!-- When you type in textBox it will AutoComplete-->
<input id="txtSiteName" type="text" />
</body>
</html>
WebService
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
private Model1Container context = new Model1Container();
[WebMethod]
public IList<string> GetAllSites(string keywords)
{
IList<string> result;
result = context.Entity1
.Where(x => x.Sites.Contains(keywords))
.Select(y => y.Sites).ToArray();
try
{ return result; }
catch
{ return null; }
}
}
}