Way for server side DataTable to write JSON to server in 1.10?
Way for server side DataTable to write JSON to server in 1.10?
epernice
Posts: 4Questions: 0Answers: 0
For server side processing, DataTables writes a (much nicer) hierarchy of objects to the server in 1.10, but it breaks ASP.NET MVC ModelBinding, which cannot handle complex hierarchies passed as serialized parameters. Would there be any way to add the ability to pass JSON to the server, rather than params? Or does this ability already exist?
I know that I could use the server side functionality in legacy mode, but I'd prefer not to. I have also asked a question on SO: http://stackoverflow.com/q/22262677/546561
I know that I could use the server side functionality in legacy mode, but I'd prefer not to. I have also asked a question on SO: http://stackoverflow.com/q/22262677/546561
This discussion has been closed.
Replies
So you might do:
[code]
$('#example').DataTable( function () {
ajax: {
url: '/data',
traditional: true
}
} );
[/code]
My understanding is that ASP.NET will be able to read that style of parameter... Perhaps you could try it and let me know? If so, I'll put that into the documentation.
Allan
Allan
I haven't tried using `ajax.data` as a function - I'll play with that when I have a chance (hopefully in a few days) and report back.
I'm wondering if it might be an idea for me to offer a plug-in method for the pre-data submit, so a plug-in could be written that would manipulate the data in a particular way - in this case reformatting into something .NET will understand natively. This single plug-in could then be shared in the community saving others the work and reducing code repetition and errors.
A nice extension might be to have a data retrieval plug-in option as well, so data such as XML, CSV etc could have similar parsers... (Note to self - if this is done, do it in a 1.10 `renderer` to benefit from per table and default options).
Interested to hear how you get on with `ajax.data` certainly.
Allan
https://github.com/ALMMa/datatables-mvc
Allan
You can easily achieve the Modelbinding with Datatables for MVC.
You just have to pass a callback function for the data property in the ajax options. The callback function than returns a json string. .NET can than handle the json and bind the data to your model. You can read more about that here
Example: