Web Service SearchBoxContext is empty

3 posts, 0 answers
  1. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 10 Feb 2014 Link to this post

    Hello,

    I'm trying to use a webapi service (based in DNN 7.2) with the RadSearchBox. Things mostly seem to be working, except that the service doesn't get the text of the search. Note that the service does get called, and, if I generate fake results, it works just fine... it just looks like the SearchBoxContext is empty. Here's what the procedure looks like:

        <AllowAnonymous()>
        <HttpPost()>
        Public Function AutoSearch(context As SearchBoxContext)
    (stuff)
    End Function

    Any ideas?

    Thanks,

    Mike
  2. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 13 Feb 2014 Link to this post

    Hello Mike,

    You have to access the context from the query string, so the parameter should look like so:
    public SearchBoxItemData[] Get([FromUri]object context)

    Then you can deserialize the context (since it comes in JSON format) and get the Text:
    JavaScriptSerializer json_serializer = new JavaScriptSerializer();
    var deserializedContext = json_serializer.DeserializeObject(context) as Dictionary<string, object>;
    string searchText = deserializedContext["Text"].ToString();

    I've attached a little sample website to demonstrate the approach.

    Regards,
    Bozhidar
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 13 Feb 2014 Link to this post

    Hello Mike,

    You have to access the context from the query string, so the parameter should look like so:
    public SearchBoxItemData[] Get([FromUri]object context)

    Then you can deserialize the context (since it comes in JSON format) and get the Text:
    JavaScriptSerializer json_serializer = new JavaScriptSerializer();
    var deserializedContext = json_serializer.DeserializeObject(context) as Dictionary<string, object>;
    string searchText = deserializedContext["Text"].ToString();

    I've attached a little sample website to demonstrate the approach.

    Regards,
    Bozhidar
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top