What parameter should I pass to Editor.Process() when using json data
What parameter should I pass to Editor.Process() when using json data
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
1. I'm developing a c# asp.net core web api application.
2. I copy the StaffController
and StaffModel
from Editor-NETCore-2.0.8 and test it OK, with the defult 'Form' action.
3. But, I want to send an application/json
request instead of multipart/form-data
request.
4. I've read the discussion https://datatables.net/forums/discussion/55370/custom-insert-update-delete-method-for-editor. which is almost the same of my case.
The problem is when I do a POST api/staff
with JSON
data (shown below), it just return all the data just like a GET api/staff
do.
{
"action":"edit",
"data":{
"DT_RowId": "row_60",
"first_name": "test1",
"last_name": "test2",
"extn": "1564",
"age": null,
"salary": 95000.0,
"start_date": "2022-06-10",
"position": "test",
"email": "",
"office": "test"
}
}
So, my question is what parameter should I passed to Editor.Process( ?? )
instead of Editor.Process( Request )
Answers
Currently I leave the parameter of
public ActionResult Staff()
to be blank, should I filled something in it?for example:
public ActionResult Staff([FromBody] ?? request)
Hi,
I don't actually think that is currently possible without transforming the JSON data in some way. There are a number of different overloads for
Process
but none of them would accept a JSON string / object.Can I ask why you want to sent it as JSON in the body rather than form data?
Allan
It's specification from a RPF owner.
From the following
and
I get the
req
object correctly,Is there still no way to processing this
req
object??No, I'm afraid not. What is really needed is to get the incoming data into a
DtRequest
object which is what the libraries use to access the submitted data.If you can get your JSON as a
IEnumerable<KeyValuePair<string, string>>
then you could pass it through theHttpData
method of that class to get the resulting object, and then use that withEditor.Process()
.Allan
I try to make use of
IEnumerable<KeyValuePair<string, string>>
, but still fail to get correct response.the Model:
the controller:
and
myConvert()
in trouble is at line 259 of DtRequest.cs
after this line
Data = http["data"] as Dictionary<string, object>;
the
Data
get a null.I'm wondering where the error comes from ? the HttpData()? or
What I was trying is wrong?
OK, I trace down into
HttpData()
which use_HttpConv()
to convert string into various type of data value, but it does not process{
and[
at all.I check the function
_Build()
, the main part of it actually make use of variablehttp
-- anDictionary<string, object>
.So, why not move the first line of it
var http = HttpData(rawHttp, culture);
out where who calls it. And then we can have another overload of functionDtRequest()
?Doesn't that fall under this constructor?
Dictionary
isIEnumerable<KeyValuePair<TKey,TValue>>
- perhaps it is just the TValue that is the issue, it should be an object...?Allan