Server-side processing: Invalid JSON primitive

Server-side processing: Invalid JSON primitive

SerberussSerberuss Posts: 2Questions: 2Answers: 0

I am trying to send data to an MVC action using server-side processing but I get the error "Invalid JSON primitive" from my browser. I've checked the JSON that I'm passing and it looks to be correct so I'm wondering whether I need a setting for the datatable? This is what I have so far:

JavaScript

var dataRows = [{ "RowCells": ["Test", "Test"] }];                                                
dataTableOptions = {
    processing: true,
    serverSide: true,
    ajax:  {
        url: "/Data/ProcessDataTable",
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({ dataRows: dataRows })
    }
};

Action

[HttpPost]
public JsonResult ProcessDataTable(IEnumerable<ReportRow> dataRows)

ReportRow class

public class ReportRow
{
    public IList<string> RowCells { get; set; }
}

I have passed the JSON to http://jsonlint.com/ and I get the message

Parse error on line 1:
0=%7B&1=%22&2=d&3=a&
^
Expecting '{', '['

I'd appreciate any help with this issue

Answers

  • allanallan Posts: 62,056Questions: 1Answers: 10,173 Site admin

    It looks like you need to have the server respond with JSON. For exactly how you do that you would need to ask in a .NET forum as I'm afraid I can't help there.

    Allan

This discussion has been closed.