I'm new to web API, and all the examples are in C# which doesn't help, as such I've hit a roadblock early on. I'm returning data from SQL, putting it an object array list, and then trying to return it so it could be read by a JSON client.
This is my default GET on my controller:
Function Index() As IEnumerable(Of String)
Dim Sites As New ArrayList
Dim dt As DataTable = DataLayer.ExecuteNoParamStoredProcedure("stored_proc", "connection_string")
For Each r As DataRow In dt.Rows()
Public Class SiteDetails
Public site As String
Public siteid As String
Public Sub New(sitename As String, id As String)
site = sitename
siteid = id
In your sample, you return an
IEnumerable(Of String). Therefore, when returning the result of your action method, all objects are converted to a string by calling the
ToString method (I suspect you have OPTION STRING turned OFF in your project); in your case, the default implementation of
ToString is used. This implementation returns the name of the type.
In order to return the data, I'd change the code as follows:
Function Index() As IEnumerable(Of SiteDetails)
ToStringmethod of the SiteDetails class so that the required data are formatted as a string correctly.
In addition, I'd propose not to use the
ArrayList class anymore; there is a strongly typed
List(Of T) class (in your case
List(Of SiteDetails) if you want to return the SiteDetails objects or
List(Of String) if you want to return strings).
Also, make sure that you are using a Web API controller. These controllers are derived from the
ApiController class (as opposed to a MVC controller that looks roughly the same, but is derived from