Trying to get JQuery Autocomplete working on Asp.Net page.
Posted
by JasonMHirst
on Stack Overflow
See other posts from Stack Overflow
or by JasonMHirst
Published on 2010-03-24T15:26:32Z
Indexed on
2010/03/24
15:43 UTC
Read the original article
Hit count: 247
Can someone shed some light on the problem please:
I have the following:
$(document).ready(function () {
$("#txtFirstContact").autocomplete({url:'http://localhost:7970/Home/FindSurname' });
});
On my Asp.Net page. The http request is a function on an MVC Controller and that code is here:
Function FindSurname(ByVal surname As String, ByVal count As Integer)
Dim sqlConnection As New SqlClient.SqlConnection
sqlConnection.ConnectionString = My.Settings.sqlConnection
Dim sqlCommand As New SqlClient.SqlCommand
sqlCommand.CommandText = "SELECT ConSName FROM tblContact WHERE ConSName LIKE '" & surname & "%'"
sqlCommand.Connection = sqlConnection
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(sqlCommand)
da.Fill(ds, "Contact")
sqlConnection.Close()
Dim contactsArray As New List(Of String)
For Each dr As DataRow In ds.Tables("Contact").Rows
contactsArray.Add(dr.Item("ConSName"))
Next
Return Json(contactsArray, JsonRequestBehavior.AllowGet)
End Function
As far as I'm aware, the Controller is returning JSON data, however I don't know if the Function Parameters are correct, or indeed if the format returned is interprettable by the AutoComplete plugin.
If anyone can assist in the matter I'd really appreciate it.
© Stack Overflow or respective owner