AutoComplete: Jquery + Asp.Net + VB.Net + MVC

  • Thread starter Thread starter ~J~
  • Start date Start date

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
Can anyone shed some light on why the hell this isn't working.

Got the following Script on my page:
PHP:
    $(document).ready(function () {
        $("#txtFirstContact").autocomplete({ source: 'http://localhost:7970/Home/FindSurname/',
                                             minLength: 3
        });
        });


And the following code in my Controller:

PHP:
    Function FindSurname(ByVal term As String, ByVal limit As Integer) As JsonResult
        Dim sqlConnection As New SqlClient.SqlConnection
        sqlConnection.ConnectionString = My.Settings.sqlConnection
        Dim sqlCommand As New SqlClient.SqlCommand
        sqlCommand.CommandText = "SELECT TOP " & limit & " ConSName FROM tblContact WHERE ConSName LIKE '" & term & "%'"
        sqlCommand.Connection = sqlConnection
        Dim ds As New DataSet
        Dim da As New SqlClient.SqlDataAdapter(sqlCommand)
        da.Fill(ds, "Contact")
        sqlConnection.Close()
        Dim a As New List(Of String)
        For Each dr As DataRow In ds.Tables("Contact").Rows
            a.Add(dr.Item("ConSName"))
        Next
        Return Json(a, JsonRequestBehavior.AllowGet)
    End Function

The 'spinning indicator' appears in the TextBox when I've typed the 3rd character, so that appears to work and accessing the Controller direct does in fact return results.

Just trying to combine the two together does absolutely nothing.

Any ideas?
 
Back
Top Bottom