[CLOSED] Load tree with WebAPI call

  1. #1

    [CLOSED] Load tree with WebAPI call

    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
    Last edited by Daniil; Apr 23, 2015 at 8:45 AM. Reason: [CLOSED]
  2. #2
    Hi @jchau,

    This example might bring some clues:
    https://examples3.ext.net/#/TreePane.../Using_Handler

    The key points that TreeLoader.ashx sets
    context.Response.ContentType = "text/json";
    and writes
    context.Response.Write(nodes.ToJson());
    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.
  3. #3
    Thanks. I will investigate further. The response content type is automatically application/json for web APIs but maybe it has to be text/json.
  4. #4
    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
  5. #5
    Nice. Thank you for sharing the solution!

Similar Threads

  1. [CLOSED] 2.2 Example tree load many times
    By devil in forum 2.x Help
    Replies: 6
    Last Post: Feb 28, 2014, 3:46 AM
  2. [CLOSED] call renderer from store load
    By Z in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Oct 14, 2013, 1:33 AM
  3. DirectEvents and WebApi json request call
    By Pyropace in forum 2.x Help
    Replies: 4
    Last Post: Sep 06, 2012, 12:42 AM
  4. Show a load mask with a DirectMethod call
    By ashwinrath in forum 1.x Help
    Replies: 2
    Last Post: Apr 21, 2012, 7:35 PM
  5. [CLOSED] Fill an entire tree in a single Ajax call?
    By juanpablo.belli@huddle.com.ar in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 23, 2009, 11:50 AM

Posting Permissions