Return XML for jQGrid as MVC ActionResult (

Posted on 2011-10-31
Last Modified: 2012-05-12

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.  

Question by:ttist25
    LVL 83

    Expert Comment

    LVL 1

    Author Comment

    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.    
    LVL 83

    Expert Comment

    >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?
    LVL 1

    Author Comment

    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.
    LVL 83

    Accepted Solution

    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.
    LVL 1

    Author Closing Comment

    Thanks boss

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now