SearchBox Client Template - DataItem not defined

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

    Posted 18 Feb 2014 Link to this post


    I'm using a client template in a search box. The box is bound to a web service and the template looks like this:
    <div class="searchResult">
          <div style="font-weight:bold;">#= Text #</div>
          <div style="font-size:.8em; font-style:italic;">#= DataItem.notes #</div>

    Things are working just fine in Chrome and IE but, in Firefox, I'm getting an error in firebug that the DataItem is not defined:

    Sys.InvalidOperationException: Sys.InvalidOperationException: Error rendering template: DataItem is not defined. There's no reason why the web service would return the dataitem for Chrome and IE but not firefox... right?

    Any ideas?


  2. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 18 Feb 2014 Link to this post

    As a follow up here... It looks like the problem is that the POST request to the web service from Firefox is going as XML, whereas from the others it goes as JSON. As a result, the result is XML, which breaks the template.

    I think I reported an issue like this a while ago - what's going on? How come this is still happening with Firefox?

  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Dimitar Terziev
    Dimitar Terziev avatar
    1266 posts

    Posted 24 Feb 2014 Link to this post

    Hi Mike,

    As discussed in the support ticket for this same problem, if the json formater is specified in the Global.asax file, the web service should return the data in JSON format which is the format supported by our controls.

    Dimitar Terziev
    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.
  5. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 25 Feb 2014 Link to this post

    Hi Dimitar,

    Thanks for your response and explanation. I didn't really want to remove the XML formatter in the global.asax file, and since this procedure is designed for use with the search box, I just handled it manually. If it helps anybody else, here's the basic code I used to get it working with WebAPI:

    Public Class SearchBoxContextDTO
        Property context As SearchBoxContext
    End Class
    Public Function SearchUsersBoxRequest(<FromBody()> postedContext As SearchBoxContextDTO) As HttpResponseMessage 'SearchBoxItemData()
        Dim output As New List(Of SearchBoxItemData)
        Dim resultItem As SearchBoxItemData
        Dim resultData As Dictionary(Of String, Object)
        Dim rsp As HttpResponseMessage = Request.CreateResponse
        Dim serializer As New JavaScriptSerializer
    '(search logic removed - fills output with results)
        If output.Count > 0 Then
            rsp.Content = New StringContent(serializer.Serialize(output.ToArray))
            rsp.Content = New StringContent("")
        End If
        With rsp
            .StatusCode = Net.HttpStatusCode.OK
            .Content.Headers.ContentType = New MediaTypeHeaderValue("application/json")
        End With
        Return rsp
    End Function

    Hope all's well,

Back to Top