Return XML for jQGrid as MVC ActionResult (


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 =, .cell = {, 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"?>
  <page> </page>
  <total> </total>
  <records> </records>
    <row id = 'unique_rowid'>
      <cell> cellcontent </cell>
      <cell> <![CDATA[<font color='red'>cell</font> content]]> </cell>

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



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.  

Who is Participating?
CodeCruiserConnect With a Mentor Commented:
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.
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:

        <jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>

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.    
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

>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?
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.
ttist25Author Commented:
Thanks boss
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.