Server-side tables processing in .NET: decoding POST data causes error 500

Server-side tables processing in .NET: decoding POST data causes error 500

TsukasaTsukasa Posts: 3Questions: 0Answers: 0
edited July 2011 in General
Hello,

I run into the following problem: I have a DataTables that I want to be handled serverside. It sends a POST ajax requests. Table is configured as follows:

[code] var oTable = $('#DataContainer').dataTable({
"bDestroy": true,
"aoColumns": data.titles,
"bServerSide": true,
"sAjaxSource": loc + "/AjaxReturnTable",
"oLanguage":
{ "sSearch": "Filter results:" },
"iDisplayLength": 25,
"bProcessing": true,
"bJQueryUI": true,
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"type": "POST",
dataType: 'json',
contentType: "application/json; charset=utf-8",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"sDom": '<"H"lfrip>t<"F"lfrip>',
"aaSorting": [[0, "asc"]]
}
);
}
[/code]

Firebug shows that in such case POST request is NOT JSON:
[code]
sEcho=1&iColumns=4&sColumns=&iDisplayStart=0&iDisplayLength=25&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true
[/code]

Problem is, that if I leave contentType, then there is a problem on server decoding POST request (NOT in my code but in ASP NET): it is expecting to be JSON. When I omit it, there is no problem (and maybe request is decoded ok, never checked) but ASP NET does not want to return my JSON string back, it returns the whole document instead! So how can I fix that?
Obviously I can not affect much how DataTables generates requests.
This discussion has been closed.