• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 876
  • Last Modified:

Return XML for jQGrid as MVC ActionResult (vb.net)

Hello,

After a week or two of agony I've finally got a working VB.NET MVC implementation of jQGrid.  Unfortunately, unbeknownst to me while I was working toward this goal, there is a maxJSONLength which I am able to exceed if I return my whole dataset.  I probably would never have a need to return the entire dataset but, if for some reason I should need to I'd like to be able to do it.  

I'm hoping that I can do it returning XML as my ActionResult.  So my question is two parts:

1.  Is there an equivalent to the maxJSONLimit if I return XML?
2.  If not, how can I convert what I've got working for JSON to return XML?

I've got the following ActionResult that returns JSON data for my jQGrid as follows:
        Public Function SelectGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As ActionResult
            Dim context As New GridDataContext
            Dim pageIndex As Integer = Convert.ToInt32(page) - 1
            Dim pageSize As Integer = rows
            Dim totalRecords As Integer = context.Students_ts.Count()
            Dim totalPages As Integer = CInt(Math.Ceiling(CSng(totalRecords) / CSng(pageSize)))

            Dim jsonData = New With { _
                .total = totalPages, _
                .page = page, _
                .records = totalRecords, _
                .rows = (From p In context.Students_ts _
                         Order By (p.LAST & " " & sord) _
                    Select New With {.id = p.id, .cell = {p.id, p.LAST, p.FIRST, p.INIT}}).ToArray()}

            Return Json(jsonData, JsonRequestBehavior.AllowGet)
        End Function

Open in new window


The jQGrid can also accept XML data if it's in the following format:
<?xml version ="1.0" encoding="utf-8"?>
<rows>
  <page> </page>
  <total> </total>
  <records> </records>
    <row id = 'unique_rowid'>
      <cell> cellcontent </cell>
      <cell> <![CDATA[<font color='red'>cell</font> content]]> </cell>

    </row>
    <row id = 'unique_rowid'>
      <cell> cellcontent </cell>
      <cell> <![CDATA[<font color='red'>cell</font> content]]> </cell>

    </row>

</rows>

Open in new window


I tried messing with an XML StringBuilder but I get an error in reference to a StringBuilder not being able to be converted to an ActionResult.

FYI - my coding skills are weak.  I'm more of a network guy.  :)

Thanks in advance for any help.  

B
0
ttist25
Asked:
ttist25
  • 3
  • 3
1 Solution
 
ttist25Author Commented:
Hey Cruiser,

Thanks for your comment.  I tried that but it still throws that error.  I've got over 65K records in my table.  

Here's what I added to my web.config:

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

Open in new window


Here's what Firebug shows under the Params tab of the error:
_search      false
nd      1320092101764
page      1
rows      10
sidx      LAST
sord      asc

Are you thinking it should still work?  It's very probable I did something else wrong.  My foundation is about as stable as a deck of cards.  :)

How about XML?  Will I run in to the same issue with XML?

Thanks again for your response.    
0
 
CodeCruiserCommented:
>How about XML?  Will I run in to the same issue with XML?

I dont know. 65K rows in an AJAX request? Do you think that's a good idea?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ttist25Author Commented:
I don't know - I'm assuming not?  It will probably never happen but you know how that goes.  If there's a way to do it with XML I'd like to be able to do it but, in the end product, records will be filtered and will return a very small subset of the table.  

Thanks again.
0
 
CodeCruiserCommented:
One of the main Pros of JSON over XML is that XML is verbose. If some data is 1MN in JSON, it may well be 5MB in XML.

About returning XML, I think you would need to construct the XML manually (using XMLDocument for example) because it is required in a specific format.
0
 
ttist25Author Commented:
Thanks boss
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now