This is a migrated thread and some comments may be shown as answers.

Web Service SearchBoxContext is empty

2 Answers 90 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 10 Feb 2014, 10:19 PM
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 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 13 Feb 2014, 03:11 PM
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.
0
Bozhidar
Telerik team
answered on 13 Feb 2014, 03:12 PM
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.
Tags
SearchBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or