No Parameterless Constructor for DtRequest
No Parameterless Constructor for DtRequest
Hello, I've been using DataTables with C# MVC sites for a bit and have been trying out Editor recently. In the past, I've made my own DTParams object to catch the parameters sent to the controller for server side processing, but in trying out Editor, I see that there's a DtRequest type included, which seems to serve the same purpose.
The one hangup I'm having is that I'm getting a 'No parameterless constructor' error when trying to use the DtRequest type for an object as a parameter for a JsonResult method that handles the data processing on the server side.
Is this the intended usage of DtRequests type, or should I continue using the params object I have in the past?
This question has an accepted answers - jump to answer
Answers
Hi,
The
DtRequest
object expects the submitted information from the client-side - normally that is the request form data (request.Form
). The method will then automatically parse the data and populate the instance.For sending data back to the client there is the
DtResponse
object, which can be used with parameterless constructor. MSDN style documentation for it is available here.That one might be more useful for sending back to the client.
Allan
Thanks for the response!
I'm afraid I might not have been clear in my usage, however. I was attempting to use DtRequest as an incoming parameter for an Action method on the server.
I had made a couple custom objects for this in the past (example):
And I was trying to use the DtRequest class as a "drop-in" replacement for that, as it seemed like that's what it was intended for. Looking at the method definitions and such, however, I don't believe that it would be compatible with this usage in it's current state, as .NET expects it to have a no-params constructor.
All that said though, datatables has been wonderful to work with, thank you very much for your hard work on it!
Ah - I see what you mean. In that case yes, I'm afraid
DtRequest
isn't going to be what you want. It populates the instance properties itself rather than that being done automatically by the framework.Allan
Thanks! It's not a big issue at all, just wanted to make sure I was making use of what I could and not making new stuff that doesn't need to be made.
Thank you very much for all your help.