View Full Version : [CLOSED] Load tree with WebAPI call

Apr 21, 2015, 9:19 PM
I set a tree's loader to a webapi action. What should be the return datatype for that action? If I return string, the tree doesn't load. I also tried returning object, but in both cases, response is wrapped in quotes.

<HttpGet> _
Public Function GetNodes() As Object
Dim nodes = GetTreeNodes()
Return nodes.ToJson()
End Function

Apr 22, 2015, 4:42 PM
Hi @jchau,

This example might bring some clues:

The key points that TreeLoader.ashx sets

context.Response.ContentType = "text/json";
and writes


response is wrapped in quotes

So, it might be OK if you set `ContentType` to `"text/json"`. Though, not sure there is such a possibility with WebAPI.

Apr 22, 2015, 4:53 PM
Thanks. I will investigate further. The response content type is automatically application/json for web APIs but maybe it has to be text/json.

Apr 22, 2015, 6:31 PM
This works:

Return New HttpResponseMessage() With {.Content = New StringContent(changes.ToJson, Encoding.UTF8, "text/json")}

So I just wrapped that up in a class for easy reuse.

Public Class RawJSONResponseMessage
Inherits HttpResponseMessage

Public Sub New(json As String)
Me.Content = New StringContent(json, Encoding.UTF8, "application/json")
End Sub

End Class

Apr 23, 2015, 7:45 AM
Nice. Thank you for sharing the solution!